function pointer bug?
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Tue Oct 28 18:22:40 PDT 2014
On 10/27/14 4:52 PM, bitwise wrote:
>>> quotes self
>
> Here is a better example, showing that virtual function pointers are
> available at compile time in C++. Essentially, I would expect my D code
> to function similarly, but it won't compile.
>
> class TestAddr {
> public: virtual void test() { cout << "test" << endl; }
> };
>
> template<void (TestAddr::*FN)()>
> class PtrWrapper
> {
> public:
> void invoke(TestAddr *instance) { (instance->*FN)(); }
> };
>
> int main(int argc, const char * argv[])
> {
> TestAddr test;
> PtrWrapper<&TestAddr::test> wrapper;
> wrapper.invoke(&test);
> return 0;
> }
That won't work in D because in D pointers to methods carry "this" with
them, whereas in C++ they don't. -- Andrei
More information about the Digitalmars-d
mailing list