Archived

This topic is now archived and is closed to further replies.

webjeff

C++ Base class question

Recommended Posts

Is this possible? I have this: ClassA : BASECLASS { public: void test() { int j = 1; } ; } class BASECLASS { public: int num=1; int runme() { num ++; }; } ///////////////CAN I do this: class someotherclass { public BASECLASS* list; storeclass(BASECLASS* class) { list = class; }; } and do it like this: --> storeclass(&classA); ???????? IS THIS POSSIBLE??? Cause ClassA isn''t BASECLASS but its base class is. How would I do this? Do I need a void* instead?? Thanks Jeff.

Share this post


Link to post
Share on other sites
Yes, it is possible, that''s the way you define interface classes.

problem may be you can''t call
someotherclass.list->test();

as "someotherclass.list" is of the type "BASECLASS" which hasn''t the "test" function defined.
You had to recast it to BASECLASS, or put "test" into the interface of BASECLASS.

Share this post


Link to post
Share on other sites