: :
: : : There were some mistakes and problems in your code. I corrected them, and this is the working code (as your desired output), in C++ (you can create classes in c++,not C, then use 'cout' instead of 'printf'). I compiled it in VC++6, as a 'Win32 Console Application'.
: : : If you have some question, I become glad to answer.

: : : Have a good coding!
: : :
: : : Code :
: : :
: : : #include <iostream.h>
: : :
: : : class Super{
: : : static int blocksize;
: : : public:
: : : static void setSize(int i){ blocksize = i; }
: : : static void printSize(){ cout << blocksize << '\n'; }
: : :
: : : virtual char operator [](int) = 0;
: : : };
: : :
: : : int Super::blocksize;
: : :
: : : class ChildOne : public Super
: : : {
: : : };
: : :
: : : class ChildTwo : public Super
: : : {
: : : };
: : :
: : : void main() // or main()
: : : {
: : : Super::setSize(1);
: : : ChildOne::printSize();
: : : ChildOne::setSize(2);
: : : ChildTwo::printSize();
: : : ChildTwo::setSize(3);
: : : Super::printSize();
: : : }
: : :
: : :
: : :
: :
: : I can't even get your code to compile.
: : Youre using #include <iostream.h> wich is old. Use the new standard.
: :
: : Also, why did you declare size outside the class again? For me it made no difference.
: :
: : Anyway I made some progress on my own yesterday and now I only have one error left.
: :
: :
: : class Super{
: : static int size;
: : public:
: : static void setSize(int i){ blocksize = i; }
: : static void printSize(){ printf("%d\n",blocksize); }
: :
: : virtual char operator [](int) = 0;
: : };
: :
: : class ChildOne : Super{
: : }
: :
: : class ChildTwo : Super{
: : }
: :
: : main(){
: : Super::.setSize(1);
: : ChildOne::printSize();
: : ChildOne::setSize(2);
: : ChildTwo::printSize();
: : ChildTwo::setSize(3);
: : Super::printSize(1);
: : }
: :
: :
: : This is my make output:
: :
: : g++ -c test.cpp -o test.o
: : block.h: In function 'int main()':
: : block.h:9: error: 'static void Super::setSize(int)' is inaccessible
: : test.cpp:5: error: within this context
: : block.h:10: error: 'static void Super::printSize()' is inaccessible
: : test.cpp:6: error: within this context
: : block.h:9: error: 'static void Super::setSize(int)' is inaccessible
: : test.cpp:7: error: within this context
: : block.h:10: error: 'static void Super::printSize()' is inaccessible
: : test.cpp:8: error: within this context
: : make: *** [test.o] Error 1
: :
: :
: : How do I make it accessesable?
: :
:
:
:
your ocmpiler probably gave you those errors because the class contains pure virtual function (operator [] ), and a class that contains pure virtual functions cannot be instantiated by themselves, and the pure virtual functions MUST be overridden in some derived class.
:
OK, this will answear both stober's and gregry's Qs.
It isn't the real code, but a simplification.
I've already implemented the operator [] func in both classes. ({}

)
The real project is about 10 files...
But the problem is that I still get that the func is inaccessible, it's not anything with the virtual class.
And what did the int Super::blocksize; line do?
It didn't make any difference.
As I said, I know more OO than C++