I had read that the C++/CLI ref class was the equivalent to a C# class. However, I'm seeing a difference between this in each class.
EDIT: I obtained this from Visual Studio 2010's locals. (Also, I noted a difference at compile time when doing exact same cast - the C++/CLI class gave an error stating it could not convert Object^ to MyClass^, whereas casting with the C# class creates no errors at compile time).
C# class:
namespace MyNamespace
{
public class MyClass
{
public MyClass()
{
//Do something
}
}
}
this = MyNamespace.MyClass (What I expect and want!)
C++/CLI ref class:
namespace MyNamespace
{
public ref class MyClass
{
public:
MyClass::MyClass()
{
//Do something
}
}
}
this = System::Object^ (Not what I expected or want!!)
I would expect this to be like the C# example, which states that this is of type MyClass. However, the C++/CLI ref class states it is of type Object.. Which is definitely NOT what I want.
(This makes it difficult in various situations, such as casting in a C++ function).
So my question is (two part):
a) why are these classes behaving differently with this?
b) how do I get my C++/CLI ref class to have the correct type in this??
Thanks for your time in advance!
What you are seeing in the debugger is the name of the base class - in this case Object^. Change the base class of MyClass to something else and you will see what I mean.

Note that the right most column displays the type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With