function prototypes in template class' (c++)
hey guys..
i have written a template class which i need to split into a .h header file with the class prototype, and a .cpp file with all the function boddies. i know how to do this, but i cant get the syntax right when i do it wilth templates.. for example, the class Code:
class chelloworld { header file (prototype) Code:
class chelloworld { Code:
#include"theHeaderFile.h" for example, how would i do the above for this class Code:
thankyou. |
You simply can't. I don't know any compiler that handles templates divided into .h and .cpp. You need to keep it in one file.
|
Quote:
programs linked againsed the shared object need to #include the shared object header file. whats the point of having a shared object if the function body is also in the header !? Compilers i know of that support this are MS Visual C++ ang GNU GCC. anyways, i managed to find an example template class program which happened to have a few function boddy's outside of the class prototype. the correct syntax for a function body outside of the prototype (for anyone else interested in the answer) on a templarte class is Code:
template<class dataType> |
While you don't have to have all the functions inline with the class declaration, when using template classes you DO need to have the full implementation of that class defined before it is used (e.g. in the header file). Object code for a template class is not produced until a specialization of that class is created. Therefore, the compiler needs to have a full implementation of a template class at the time of compilation.
Here's a thread where this has been discussed before. Note that there is a way that the C++ spec allows you to separate the header and implementation via exported template, but to the best of my knowledge, there are only 1 or 2 specialized compilers that support this. Neither of which is g++ or VC++. (And at a MS TechEd session I once was at a couple years ago, I seem to recall the speaker saying that VC++ would probably never support this feature due to the complexity.) |
so if i understand correctly... ist impossible to put a template class in a .so shared object ?
at compile time of the application that uses the shared object always has the class' header file, with all the function prototypes, isnt this enough ??? ive almost finished codeing the cliant program for the shared object... but the template class template object compiled fine, g++ ididnt complain at all. edit: (jest read the link, and the link in the link) makes sence now.... well this is annoying.... i use the same HUGE class in almost all of my Artificial inteligence courseworks ! i thought it would be great to dynamically link it, rather than compile i over and over and over... ohh well, looks like i ve got to compile and statically link it to all my works.. lame :( |
All times are GMT -5. The time now is 04:01 PM. |