I've lots of classes with similar interface. The following class is a placeholder of other classes:
Code:
class Derived : public Base {
	static int x;
public:
	Derived() {x = 10;}

	static int get_x() {return x;}
};

int Derived::x = 0;
Note that get_x() is needed to be a static function for all of the classes. Now I need to access a Derived* through a Base*:
Code:
int main()
{
	Base *b = new Derived;
	cout << b->get_x() << endl;

	delete b;
	return 0;
}
My problem is I'm failing to design such a Base class that will allow the above code in main(). b->get_x() should execute the proper derived class's get_x() it is pointing to. Since get_x() must be a static function, I cannot use a virtual method for my Base class. I tried the following versions:
Code:
class Base {
public:
	virtual int get_x() {return -1;}
};
which returns -1 always and
Code:
class Base {
public:
	virtual int get_x() = 0;
};
with error in Visual C++ 2005: error C2259: 'Derived' : cannot instantiate abstract class.
Can you help me to design a Base class to allow the code in main()? Thanks for reading this.