The effect of "^"

M

Maxim

Hi, All!

What is the effect of using ^ with the managed type? I'm trying to create a
class library in managed c++. There is a class:

public ref class MyClass

{

public:

IntPtr^ WindowHandle;

int^ SomeNumber;

};

When I use this class in another project (C#) it is shown as

public class MyClass

{

public ValueType SomeNumber;

public ValueType WindowHandle;

public MyClass();

}

When I use type declarations without "^" the imported class becomes

public class MyClass

{

public int SomeNumber;

public IntPtr WindowHandle;

public MyClass();

}

I thought that I should always use ^ with managed classes. Could somebody
explain me that? Sorry for such a stupid question, but I'm new to Managed
C++.

Thanks in advance.
 
G

Guest

The normal use of "^" is with reference types, not value types, so you would
normally not use it with 'int' for example, but you would use it with
'System::String' for instance.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
A

Arnaud Debaene

Maxim said:
Hi, All!

What is the effect of using ^ with the managed type? I'm trying to create
a class library in managed c++. There is a class:

public ref class MyClass

{

public:

IntPtr^ WindowHandle;

int^ SomeNumber;

};

When I use this class in another project (C#) it is shown as

public class MyClass

{

public ValueType SomeNumber;

public ValueType WindowHandle;

public MyClass();

}

When I use type declarations without "^" the imported class becomes

public class MyClass

{

public int SomeNumber;

public IntPtr WindowHandle;

public MyClass();

}

I thought that I should always use ^ with managed classes. Could somebody
explain me that? Sorry for such a stupid question, but I'm new to Managed
C++.

Yes, you should always use ^ with managed *classes* (that is, reference
types, which are written "class" in C#). The problem is that both IntPtr and
int are value types ("struct" or primitive type in C#). They are therefore
created on the stack (as opposed to the managed heap) and don't require the
caret.

Arnaud
MVP - VC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top