Templates && Visual C++ 6.0

Started by
4 comments, last by Divide 21 years, 5 months ago
Hey again, I've had some weird problems with templates. I compile one project to a lib and another one to a plain exe file. What I'm doing comes down to this: [lib part]
  
template<class T>
class bla {
  public:
  void doSpeak( T jadda ) {
    cout << jadda << "\n";
  }
}

//! Should instances of templates in the same file

bla<int> crapTemplateFix;

class speech : public bla<char> {
}
  
[exe part]
  
 speech test;
  
In debug mode it compiles smoothly. However, when I want to optimize for speed in release mode I get unresolved externals. I figured somehow he "optimizes" the crapTemplateFix out of my code. Work arounds / solutions anyone ? [edited by - Divide on November 18, 2002 8:48:08 AM]
Advertisement
what are the messages?
Where is craptemplatefix defined? It should be in a source file, not a header.

Workaround: buy VC++.Net. VC 6 has plenty of problems with templates.

Cédric
quote:Original post by petewood
what are the messages?



  libgui.lib(cdropdownlistbox.obj) : error LNK2001: unresolved external symbol "public: void __thiscall ai::gui::control::base::bcontainercontrol<class ai::gui::control::base::bcontrol *>::addControl(class ai::gui::control::base::bcontrol *)" (?addControl@?$bcontainercontrol@PAVbcontrol@base@control@gui@ai@@@base@control@gui@ai@@QAEXPAVbcontrol@2345@@Z)test.obj : error LNK2001: unresolved external symbol "public: void __thiscall ai::gui::control::base::bcontainercontrol<class ai::gui::control::base::bcontrol *>::addControl(class ai::gui::control::base::bcontrol *)" (?addControl@?$bcontainercontrol@PAVbcontrol@base@control@gui@ai@@@base@control@gui@ai@@QAEXPAVbcontrol@2345@@Z)libgui.lib(cpropertypanel.obj) : error LNK2001: unresolved external symbol "public: void __thiscall ai::gui::control::base::bcontainercontrol<class ai::gui::control::base::bcontrol *>::addControl(class ai::gui::control::base::bcontrol *)" (?addControl@?$bcontainercontrol@PAVbcontrol@base@control@gui@ai@@@base@control@gui@ai@@QAEXPAVbcontrol@2345@@Z)libgui.lib(ctabpanel.obj) : error LNK2001: unresolved external symbol "public: void __thiscall ai::gui::control::base::bcontainercontrol<class ai::gui::control::base::bcontrol *>::addControl(class ai::gui::control::base::bcontrol *)" (?addControl@?$bcontainercontrol@PAVbcontrol@base@control@gui@ai@@@base@control@gui@ai@@QAEXPAVbcontrol@2345@@Z)libgui.lib(ccheckboxgroup.obj) : error LNK2001: unresolved external symbol "public: void __thiscall ai::gui::control::base::bcontainercontrol<class ai::gui::control::base::bcontrol *>::addControl(class ai::gui::control::base::bcontrol *)" (?addControl@?$bcontainercontrol@PAVbcontrol@base@control@gui@ai@@@base@control@gui@ai@@QAEXPAVbcontrol@2345@@Z)test.obj : error LNK2001: unresolved external symbol "public: void __thiscall ai::gui::control::base::bcontainercontrol<class ai::gui::control::output::clabel *>::addControl(class ai::gui::control::output::clabel *)" (?addControl@?$bcontainercontrol@PAVclabel@output@control@gui@ai@@@base@control@gui@ai@@QAEXPAVclabel@output@345@@Z)../debug/test.exe : fatal error LNK1120: 2 unresolved externals  



quote:Original post by cedricl
Where is craptemplatefix defined? It should be in a source file, not a header.

Cédric


It has been defined inside a source file.
why do you need that specialisation in the header? that would be a global variable which you shouldn''t define in a header.

quote:Original post by cedricl
Workaround: buy VC++.Net. VC 6 has plenty of problems with templates.


that''s a pretty expensive workaround. what about using gcc for free?
quote:
that''s a pretty expensive workaround. what about using gcc for free?


Compiles just fine under gcc ^_^
But, I want a work around using VC++, since the company prefers that

This topic is closed to new replies.

Advertisement