function pointer bug?

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 27 16:36:17 PDT 2014


> this means that something gone wrong in the process. 
> '(__error)' is the
> "pseudotype" for failed CTFE/instantiation.

But why did the instantiation fail? and more importantly, why did 
it not have consistent behaviour between the two templates above?


>what do you want to achieve
>with second enum?

I'm just trying to come up with a test case which may offer some 
insight into what's going wrong with the code in the OP.

for example, I am wondering how far this issue extends; meaning, 
is it only classinfo.vtbl that's not available at compile time? 
or is it the address of member functions as a whole that are 
unavailable?

The code below suggests the latter, although it doesn't 
explicitly state it:

static addr = &TestClass.instanceMethod;
Error: non-constant expression & instanceMethod

I may be missing a subtle difference, but in C++, this code works:

class TestAddr {
     public: virtual void test() { cout << "test" << endl; }
};

int main(int argc, const char * argv[])
{
     TestAddr test;
     static auto ptr = &TestAddr::test;
     (test.*ptr)();
     return 0;
}

so why would it not in D?



More information about the Digitalmars-d mailing list