function pointer bug?

Kapps via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 28 01:08:41 PDT 2014


On Monday, 27 October 2014 at 22:17:25 UTC, bitwise wrote:

> This error seems like it may be related some how:
>
> enum index = __traits(getVirtualIndex, 
> TestClass.instanceMethod);
> enum p = TestClass.classinfo.vtbl[index];
>
> The above code will produce this error:
> Error: typeid(main.TestClass).vtbl is not yet implemented at
> compile time
>
> but if this is the problem, shouldn't Both of the test cases 
> fail?

You shouldn't need the vtbl at compile-time, only the index of 
the method. The method indices within the vtbl are computed, 
which is what getVirtualIndex gives you, but CTFE doesn't support 
directly accessing the vtbl yet. That being said, you only need 
to worry about any of this if you want to support virtual methods 
and have it invoke the actual overridden method, not the one you 
have saved through reflection. (For example, if Bar : Foo 
overrides foo, and you generated reflection info for Foo, it 
would call Foo.foo instead of Bar.foo even if passed in an 
instance of Bar.)

It's hard to tell exactly what you're trying to do in your 
original code, but one thing to keep in mind is that something 
like Foo!(TestClass.TestInstance) may mean multiple things, as 
the method has overloads. At some point you may need to use 
__traits(getOverloads) (such as in 
https://shardsoft.com/stash/projects/SHARD/repos/shardtools/browse/source/ShardTools/Reflection.d?until=45ded3019f3f05d7b68e5746d34da1de7433ccf6#1202) 
to get the actual methods which you can then get a function 
pointer for (again though, requires more effort for properly 
handling virtual methods).


More information about the Digitalmars-d mailing list