C++ class defined within templatized class ctor compiles but does not link?
I have a templatized class that defines a class within it but I have extrated the constructor/destructor definition for the class within it to be defined outside of both classes because of cross referencing issues:
In essence I have something like the following:
template < typename T, unsigned int MaxResourceID >
class ResourceManager: public Singleton < T >
{
public:
class handle
{
private:
unsigned int id, refctr;
public:
handle(unsigned int Id);
~handle();
};
};
template < typename T, unsigned int MaxResourceID >
ResourceManager < T, MaxResourceID >::handle::handle(unsigned int Id)
{
//code code code
}
template < typename T, unsigned int MaxResourceID >
ResourceManager < T, MaxResourceID >::handle::~handle()
{
//code code code
}
When I try to derive a concrete class from ResourceManager I get 2 link errors saying that the constructor and destructor for handle were not defined.
example:
class TestRM: public ResourceManager < TestRM, 5 >
{
};
TestRM::handle *h;
h= new TestRM::handle(0);// calling handle ctor causes link error
delete h; // calling handle dtor causes link error
I am compiling under VC6.
"With these guns and opium we can do anything!" - crazy anime pirate guy
[edited by - MegaManSE on September 8, 2002 2:47:22 PM]
What is the point of making resource manager a template class? I think you should be able to solve this problem more easily by rethinking your design, unless you have a special purpose for a template class (it doesn't look like it from what I see.)
EDIT: nevermind, couldn't see whole post due to html tags...
[edited by - Neosmyle on September 8, 2002 2:52:50 PM]
EDIT: nevermind, couldn't see whole post due to html tags...
[edited by - Neosmyle on September 8, 2002 2:52:50 PM]
The reason I am making a templatized resource manager class is so that I have a generic way of handling resource management for things like actors, sounds and texture management all in one convenient way. I plan on deriving from this class a string resource manager class that will resolve for example filenames to id''s so that it makes more sense to derive from that class my sound manager, actor manager and texture manager classes.
"With these guns and opium we can do anything!" - crazy anime pirate guy
"With these guns and opium we can do anything!" - crazy anime pirate guy
Ok, some questions:
1. Why declare handle in ResourceManager? You would be better off simply putting all of the classes in a namespace if it is a large project, rather than declaring it in the template.
2. Why derive ResourceManager from Singleton? -or- Why derive TestRM from ResourceManager. You aren''t really using templates as you should, because you are both deriving the classes and templatizing them.
I don''t know. It all just seems very hazy to me, but there are probably special circumstances, and I''m not very experienced with templates (recently moved to c++ from c).
1. Why declare handle in ResourceManager? You would be better off simply putting all of the classes in a namespace if it is a large project, rather than declaring it in the template.
2. Why derive ResourceManager from Singleton? -or- Why derive TestRM from ResourceManager. You aren''t really using templates as you should, because you are both deriving the classes and templatizing them.
I don''t know. It all just seems very hazy to me, but there are probably special circumstances, and I''m not very experienced with templates (recently moved to c++ from c).
If you are using Visual C++, you must define the nested class''s member functions in the class definition, not outside. VC++ has a few standards compliance issues like these, but most have workarounds.
If this is indeed the case then my problem is unsolvable because the reason I defined the ctor/dtor was that I have a STL map of handles inside the resourcemanager that the ctor/dtor of the handle class references in their code. So as you can see the handlemap relies on the entire class handle already being defined and class handle ctor/dtor rely on handlemap being defined.
"With these guns and opium we can do anything!" - crazy anime pirate guy
"With these guns and opium we can do anything!" - crazy anime pirate guy
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement