I struggling with a problem, that i don’t know if has solution.
I have a base class ( a pure interface ):
A.h
class A {
public:
static void myMethod()=0;
}
and some derived class of the type:
B.h
#include "A.h"
class B : A {
public:
static void myMethod();
private:
B();
}
C.h
#include "A.h"
class C : A {
public:
static void myMethod();
private:
C();
}
with private constructor.
I want to call from the static method of the base class (interface) the static method specialized by the derived class, but i don’t see a solution for this.
For example if i want to declare a map of this type:
std::map<int,A*> idToType;
B* b;
C* c;
...
idToType.insert ( std::pair<int,A*>(1,b) );
idToType.insert ( std::pair<int,A*>(2,c) );
...
idToType.at(1)->myMethod(); // this line does not work
and use it to call the static method implemented by derived as in the above example, but it seems impossible to do.
There is a way to do this?
If not, there is an explanation?
Thank you.
Source: Windows Questions C++