Sign in to follow this  
KevinLee

How to declare a private function of template?

Recommended Posts

Hi, I wonder if there any way that I can separate declare a private function of a template class? Usually, we detail all implementation code in a .h file, so, how can I declare a private function, I mean that I just want to give the definition to client users and I take care of the source code of these template member functions. Thanks in advance!

Share this post


Link to post
Share on other sites
Long answer:
The standard defines the 'export' keyword to do what you want to do. What it allows is defining templated functions in a different translation unit from the declaration of that function, a.k.a. what you want to do.

Short answer:
No.

There are very few (one EDG's?) compiler that supports the 'export' keyword because it is extremely difficult to implement, and in general not worth the effort. It also supposidly greatly lengthens compile times. MS compilers do not support it, and last I checked g++ doesn't either. I wouldn't hold my breath waiting for people to implement it either. For now you have to define all the members of a template class in the same file as the declaration.

Share this post


Link to post
Share on other sites
For templates, you can't because the implementation depends on the template parameters. However, some compilers support export, which does what you want.

Share this post


Link to post
Share on other sites
I found that the latest MS compiler VC2005 supports template better than VC 6.0, for example, template template parameters...etc.

Do you guys use template frequently in your projects?

Share this post


Link to post
Share on other sites
VC8 for sure does not support 'export.' The only compiler I have heard about that does is Comeau 4.3.3 which uses EDG's frontend. There are several high profile C++ community members trying to get 'export' taken out of the language. Even so it IS a keyword according to the standard (14.0.6), but I would recommend not using it even if you got your hands on a compiler that supported it. You are pretty much stuck defining all templated classes and members within the same header.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this