void (Foo::^p)()=&Foo::bar; // won't compile

  • Thread starter Thread starter Ray Tayek
  • Start date Start date
R

Ray Tayek

hi, trying to make an array of function pointers to make delegates with.
but the compiler does not like: void (Foo::^p)()=&Foo::bar;

i did find an article that showed how to convert a delegate to a
function pointer, but i sorta want to go the other way around.

thanks


class Foo { public: void bar() {} };
class Baz {
void qux() {
void (Foo::*p)()=&Foo::bar; // works fine
}
};
ref class RFoo { void bar() {} };
ref class RBaz {
void qux() {
void (Foo::^p)()=&Foo::bar; // C2589 C2143 C2059
}
};
 
Ray Tayek said:
hi, trying to make an array of function pointers to make delegates with.
but the compiler does not like: void (Foo::^p)()=&Foo::bar;

i did find an article that showed how to convert a delegate to a
function pointer, but i sorta want to go the other way around.

thanks


class Foo { public: void bar() {} };
class Baz {
void qux() {
void (Foo::*p)()=&Foo::bar; // works fine
}
};
ref class RFoo { void bar() {} };
ref class RBaz {
void qux() {
void (Foo::^p)()=&Foo::bar; // C2589 C2143 C2059
}
};

instead of your managed function pointer, you should define

delegate void MyDelegate();

Once you have done that, you can instantiate it:

MyDelegate^ d = gcnew MyDelegate(&RFoo::bar);

Once you have instantiate it, you can invoke it:

d->Invoke();
 
instead of your managed function pointer, you should define

delegate void MyDelegate(); ... you can invoke it:

yes, that works fine. i was hoping to initialize an array of function
pointers to use to create the delegate.

thanks
 
Back
Top