Show template function in the classes windows
Simon Drouin
sdrouin at bic.mni.mcgill.ca
Wed May 18 13:12:44 BST 2005
Christophe Guilbert wrote:
> For a reason which is too hard for me to understand ! the template
> need to be define in the header file,
I think there is no way to put the implementation of template functions
in .cpp classes. The reason for that is that the compiler instanciate a
specialisation of a template function for every type it is used with.
For example, if you have the following code in a .cpp file:
vector<int> vec1;
vector<float> vec2;
The .o file generated for this cpp will contain 2 implementations of the
vector class. You can see from this example that it is impossible to
compile a template until you know what it will be used for. That's why
it needs to be in .h.
Compiling templates in cpp files would mean that somehow, the .o
generated contained some kind of binary representation of templates. But
then, you would need to do some kind of compilation when you link, which
does not make much sense with the way compilers and linkers work.
This is not the answer to your questions, but I hope it helps.
Simon.
-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«
More information about the KDevelop
mailing list