Quote:Original post by Jaiminho
Quote:Original post by Vorpy
Make the do_stuff method virtual. In the code you're trying to simplify, it looks like you're just using run-time type information when you could just call a virtual method.
Would be that simple, yes, but that was just an example. I need to use some members that super class doesn't know about and can't do that simply with virtual methods.
------------------
Ok... it shows no error on method, but does on usage:
*** Source Snippet Removed ***
I'm on GCC, BTW. Doing some console output inside f() gets me what I tell to print in Sub's method. This is strange.
The problem is quite clear, you are trying to retrieve member "x" from an object of type "Super", which declares no such member. Remember that such type checking is done at compile time, C++ doesn't even take into consideration the fact that the return value may be of a derived type. What the C++ compiler sees is:
0) I have a Super object pointer
1) I call f() on it
2) according to class Super{}; that returns a Super reference
3) Now lets get its member x... wait a minute, a super doesn't have a "x"...
error and dieI think it would be better for you to explain to us what you are actually trying to do, because there may be a better way to go about it.