Archived

This topic is now archived and is closed to further replies.

Templates && Visual C++ 6.0

This topic is 5505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 *)" (?addCon
trol@?$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 *)" (?addContr
ol@?$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 *)" (?addContr
ol@?$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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites