AlionSolutions
April 25th, 2003, 06:23 AM
Hi,
I'm in some trouble again, and I bet someone of you has got the solution ;o)
I built a class that keeps track of the existing instances of the class. I decided to have a static class member of type std::map the key should be some integer-value identifying the actual instance, the value should be a pointer to the object itself.
The class looks like this:
class MyClass
{
private:
map<int,MyClass*> m_ClassMap;
public:
MyClass()
..
..
}
So far, so good. In the Constructor each of the instances shall register itself to the classmap. Therefore I put this inside the constructor:
m_ClassMap[inst] = this;
where inst is a value of type integer, for identifying a particular instance later.
Ok,when I compile it I get a linker-error telling me, that there is an unresolved external MyClass::m_ClassMap. Does anybody know why ? I don't...
To describe why I do the things explained above: Because of Win32-Architecture I have to build one function of my class as static to avoid global functions. Win32API wants a function-pointer and is not very amused about class-methods because of the implicit this-pointer they have.
For that reason I decided to make one static function for handling all. This function gets the Id of the actual instance and looks up this id in the map described above, gets the associated instance-pointer and calls a function upon it.
I think this is the easiest way to handle with this case, anyway I would appreciate any suggestions to get this done in a better way.
But for now: Why do I get this Linkererror ?
Thanx in advance
Juergen
I'm in some trouble again, and I bet someone of you has got the solution ;o)
I built a class that keeps track of the existing instances of the class. I decided to have a static class member of type std::map the key should be some integer-value identifying the actual instance, the value should be a pointer to the object itself.
The class looks like this:
class MyClass
{
private:
map<int,MyClass*> m_ClassMap;
public:
MyClass()
..
..
}
So far, so good. In the Constructor each of the instances shall register itself to the classmap. Therefore I put this inside the constructor:
m_ClassMap[inst] = this;
where inst is a value of type integer, for identifying a particular instance later.
Ok,when I compile it I get a linker-error telling me, that there is an unresolved external MyClass::m_ClassMap. Does anybody know why ? I don't...
To describe why I do the things explained above: Because of Win32-Architecture I have to build one function of my class as static to avoid global functions. Win32API wants a function-pointer and is not very amused about class-methods because of the implicit this-pointer they have.
For that reason I decided to make one static function for handling all. This function gets the Id of the actual instance and looks up this id in the map described above, gets the associated instance-pointer and calls a function upon it.
I think this is the easiest way to handle with this case, anyway I would appreciate any suggestions to get this done in a better way.
But for now: Why do I get this Linkererror ?
Thanx in advance
Juergen