void* equivalent

  • Thread starter Thread starter Nanditha Chandra
  • Start date Start date
N

Nanditha Chandra

Hi!

I am new to Managed C++ and am working on my first project with this.

In native C++, we could have a function that takes void* and call that
function with any type. Is there a way to do that with MC++? If I had
something as follows in native C++,

Foo(void* arBuf, int nSize);

And this can be called as follows

int* nBuf = new int[nSize];
Foo(nBuf, nSize);

long* nBuf2 = new long[nSize];
Foo(nBuf2, nSize);

How would I do something like this in MC++? I have an array of Byte
and int (and possibly others as well). And I need to pass this to a
function which can handle both (Similar to the Foo function above). I
am not sure how that Foo function has to be defined in MC++?

Also an additional question - What exactly is IntPtr? Is it void
equivalent?

Thanks,
D
 
Nanditha,
I am new to Managed C++ and am working on my first project with this.

In native C++, we could have a function that takes void* and call that
function with any type. Is there a way to do that with MC++? If I had
something as follows in native C++,

Foo(void* arBuf, int nSize);

And this can be called as follows

int* nBuf = new int[nSize];
Foo(nBuf, nSize);

long* nBuf2 = new long[nSize];
Foo(nBuf2, nSize);

How would I do something like this in MC++? I have an array of Byte
and int (and possibly others as well). And I need to pass this to a
function which can handle both (Similar to the Foo function above). I
am not sure how that Foo function has to be defined in MC++?

You'd probably want Object*, since all managed types derive from Object.
That said, you'd need to box value types...
Also an additional question - What exactly is IntPtr? Is it void
equivalent?
Not quite. It is mostly used for interop where you need to handle values of
pointers (possibly pointing to unmanaged memory).
 
Back
Top