Is there some constrain for making 'map' static or do I
miss something? Ideally I would like to have a singelton
class with a map container.
Actually, I don't have this problem if I define my static
as a pointer to map instead of just map and I do
initialization of this pointer to NULL in the source file.
Maybe I should do any kind of initialization of the static
map but I don't know how to do it.
thanks in advance,
Marina
When you declare a static member of a class, you also need to define it
somewhere, e.g.:
// MyClass.h
#include <map>
class MyClass
{
static std::map<int,int> sm_map;
// other members of MyClass.
};
// MyClass.cpp
#include "MyClass.h"
std::map<int,int> Myclass::sm_map; // definition for static member.
-cd
#include "MyClass.h"
std::map<int,int> Myclass::sm_map; // definition for
static member.
I'm getting the following compilation error:
"Myclass::sm_map : definition of dllimport static data
member not allowed"
What can I do in such situation?
>.
>
My instinct would be to put your map in another class that you are not
exporting and provide and interface to it through your exported class.
Think pimpl.
HTH
Andy.
I have done some testing and discovered that this is not necessary.
I was able to use and exported a class from a dll with static member no
problem.
If you are interested I can send the code - I am using it on Visual
Studio.Net - but have also tested on v6.
Let me know which version you are using.
I am assuming that your exported static is private - and clients access it
via public member functions of you class?
Can you give some more detail - were you compiling the dll or the client exe
when you got this error ?
> Think pimpl.
Although not strictly necessary to solve you problem - not a bad idea in any
case.