I want to be able to call virtual function (vfunc) in two differents classes (one derived in another)..
for instance:
Code:class derived { public: derived() { } void run() { vfunc(); } virtual void vfunc() { } }; class someclass : public derived { public: someclass() { } void vfunc() { std::cout << "someclass virtual function called\n"; } }; class baseclass : public someclass, public derived { public: baseclass() { } void vfunc() { std::cout << "baseclass virtual function called\n": } }; void main() { baseclass test; test.run(); //will print baseclass virtual.. //how to call vfunc that is inside someclass with test.run(); //is this possible? }
In other words (I know it sounds complicated):
I want to be able to print "baseclass virtual.." and "someclass virtual.." from baseclass (test) by calling run.
The reasons I want to do this is i'm working on my thread class that will be derived in other classes with virtual functions, and they will
be derived into main class which will also have the same virtual function (thread class is used to create thread and call virtual function) and
I want to keep all data in the same class (main class with derived classes) so I wouldnt have to pass the reference to main thread to the other (worker) threads/classes.
I hope you know what I mean.. Thanks for help