Function pointer for GC

Is there a workaround for passing pointer to a member function of a gc class
I know I can use delegate but I don't want to.

Thanks
P


Answer this question

Function pointer for GC

  • Philip Borchert

    I do not think there is a concept of function pointers at the CLI language level.

    Pinning pointers refer to class data (or the class itself), not methods of a class.


  • John J. Adams

    You are almost there - the correct syntax is:

    foo(d, &galvac_c::foo);



  • Hicham_IT

    I am sorry, thats a typo.
    The reason I posted because I am getting a compiler error (C3374) . My question should be reformatted to : Can I pass pointer to member function of a Managed class to un-managed class without using delegates.

    If I CANNOT then I will just use delegates instead.

  • Guillermo Leal-Collazo

    Is this valid even if the function is static In case of object what if I pin the object

  • Rockfan

    No: this is not possible. There is really no such think as a pointer-to-member for a managed class (the internals of a managed class are completely managed by the CLR and hence you can't create such a thing). You'll have to use a delegate for this purpose.

  • Othmane Rahmouni-MSFT

    By pinning an object we won't let GC to move our object. So that it will have a fixed address. Anyway, I will use delegates...



  • Rj_murray

    A non-gc heap. Here is a pseudo code:
    __gc struct galvac_c {
    ....
    int **d;
    static void foo(galvac_c *instance, int *a) {
    ....
    }
    };
    void boo( galvac_c* inst, void (*foo)( galvac_c* ,int)) {
    ...
    foo(inst,cur_num);
    ...
    }
    int _tmain {
    galvac_c *d = new galvac_c();
    foo(d,galvac_c::foo);
    }

  • adrianol

    Are you asking about passing a pointer to an allocation on the gc heap, or on the non-gc heap

  • Function pointer for GC