How to declare a private function of template?

Started by
5 comments, last by Dranith 18 years, 4 months ago
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!
Advertisement
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.

For templates, you can't because the implementation depends on the template parameters. However, some compilers support export, which does what you want.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
So, I wonder if 'export' is really a standard c++ keywords to template?
Anyway, thanks you guys.
:)
It is, but only a handful compilers fully implement the C++ standard (especially the template parts).
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?
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.

This topic is closed to new replies.

Advertisement