Advertisement

template classes causing link errors...

Started by April 11, 2000 04:43 PM
17 comments, last by noxa 24 years, 8 months ago
i tried it out, it''s actually _export.
but now the linker complains that this is an obsolete keyword... weird, my c++ book claims it would be export, but that even doesn''t exist.
anybody?
Whether you need to include the template function/class definition and code in the same file is compiler dependent. Visual C++ 6.0 can handle them in seperate files. Other compilers require that they be in the same file.

Michael L. Roberts
aka milo
mlbobs@telocity.com
Advertisement
well, actually MY visual 6.0 gives me linker error if i put them in seperate files. that''s because templates are not accessable from other compiler units unless you declare them as export.
Not that it means much, but a couple weeks ago I was stuck with exactly the same problem.

It resulted in mass confusion for a week or so until I accidentally discovered the cause. See, not having done any templates before, I was unaware that you needed the body with the header.

Confusing, eh?



regards,

GeniX
regards,GeniXwww.cryo-genix.net
Ridcully: How do you declare them as export? The export keyword doesn''t exist in VC 6.0a, and _export meets with compiler errors saying that it is non-standard and not supported.


- null_pointer
Sabre Multimedia
I''m not sure that VC6 supports ''export''. Very few compilers do right now (if any). After realizing the problems that templates might cause (this problem specifically) they added the export keyword that would require the implementation to be able to delay instantiation and such and link in template functions as though they were normal. Of course, since it''s probably one of the most difficult parts of the standard to implement, and since most people are used to just writing everything in the .h files, it''s not a priority for most compiler vendors.

Also, export does not seem to be an optional feature. That section of the standard (it''s littered throughout chapter 14) is somewhat vague in what export should allow, but it does make the following statement (chapter 14, paragraph 9):


Note: an implementation may require that a translation unit containing the definition of an exported template be compiled before any translation unit containing an instantiation of that template.


I wish I was a better language lawyer for these issues. Oh well...

-Brian
Advertisement
well, some weeks ago i was stuck with the same problem, and looked up what my c++ game said to this, and it said you have to declare your functions with export.
i tried that, and you''re right, vc6 doesn''t support it.
so i put an underscore before it, and although it complained about it being obsolete, it compiled without linker error.
then, today, i compiled it again, and it DID NOT compile.
so i think osmanb is right, it''s not support although it should be part of the standard
In Microsoft C (and VC++), the _export keyword has been renamed to __export and then replaced by __declspec(dllexport). However these key words are used to export functions, data, etc. in a DLL without the need to add entries to a .DEF file.

Which is a totally different beast than the export keyword from the standard.

Tim
All I can say is that I hope VC++ gets its act together with template classes by version 7.0 -- it can''t list template class member functions from a namespace in its ClassView window, and it cannot list template class sub objects'' member functionsin ClassView either. It also cannot do template class sub objects outside the class definition.


- null_pointer
Sabre Multimedia

This topic is closed to new replies.

Advertisement