Hi Jerome,
I can read methods of class Test, but not methods of Test1 , using this code.
(In fact I can read them if Test1 stops inheriting from Test)
What I'm missing?
cheers
When a base class defines a virtual method, all derived classes will only override that particular method (regardless of whether it is declared as 'virtual' or not in the derived class).
So those virtual methods would only be listed in the base class. You can use c.base to access the base class for that method. The values for the overridden methods themselves would be in the derived class 'vTbl' member.
With virtual methods, invoking the method from an instance of either the base or derived class will result in the derived class method being called.
Please let me know if you need any further clarifications I will be happy to answer in detail.
Yes you can. But for virtual methods, the Method information only exists in the class where the method is defined, not in the class where it is overridden.
The only thing that the derived method specifies is the function pointer to which it was overridden.
Hence why in your earlier example you if you have:
Class test1Class = class(Test1);
You will want to search for the 'setup' method in the base class of Test1, e.g. test1Class.base (Which will be class(Test) )
For instances, e.g.:
Test1 a { };
You can access the class and then access method from the class:
a._class.base
But instances can also override the virtual method pointers themselves, so for the function pointers you would access a._vTbl[<methodID here>]. The method ID will be the 'vid' within the Method object.
This is all rather internal details though, so depending on what you are trying to achieve there might be an easier way to do it.
Now I see.
I forgot to explicitly define methods as public.
Then something else joked me: virtual methods are always visible
(where visible means reachable via class.methods tree)