Using C++ separation model for function template instantiation

S

sonnu

I have a func template declaration in "func_template.h" header and
have the definition under "func_template.cpp" as shown below.

Questions:

1.0 How can I make use of the template declaration from a diffrent CPP
file. My intention is not to expose the implementation details to the
client code. Is this possible?
2.0 Can I make this particular template instantiation exclusive for a
single file, I mean I want to achieve what a "STATIC" keyword achieve
in C for a func decl/defn.
3.0 Can I get the list of standard compilers available which supports
this model of template instantiation?

//File func_template.h

template<typename T, int size>
T Median(T (&_m)[size]);

template<typename T, int size>
T Deviation(T (&_m)[size], T _val);
//End func_template.h



//File func_template.cpp
template<typename T, int size> <------------As C++ standard
documentation states, including "export" keyword gets compile error
T Median(T (&_m)[size])
{
//Do something
return _m[1];
}

template<typename T, int size>
T Deviation(T (&_m)[size], T _val)
{
if(size > 0)
{
//do something
}
return T(0);
}



//File consumer_temp.cpp

#include "func_template.h"

int main(int argc, char* argv[], char** _environ)
{

int rc = -1;

int trng_data[4] = {1,2,3,4,5};
int lol = Median(trng_data); <--------- Gives me Linking Error
under VS2005 compiler????

exit(rc);

}
 
K

Kai-Uwe Bux

sonnu said:
I have a func template declaration in "func_template.h" header and
have the definition under "func_template.cpp" as shown below.

Questions:

1.0 How can I make use of the template declaration from a diffrent CPP
file. My intention is not to expose the implementation details to the
client code. Is this possible?

Only if you use "export".

[snip]
3.0 Can I get the list of standard compilers available which supports
this model of template instantiation?

As far as I know, only Comeau supports export.

[snip]


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top