I come across some MC++ code like this:
__gc class ClassA
{
Puclic:
ClassB GetClassB();
}
__gc class ClassB
{
Public:
int Value;
}
int main()
{
ClassA^ a = gcnew ClassA();
ClassB^ b = a->GetClassB();
int c = b->Value;
}
Isn't it important to check whether b is NULL before access to its value? I tried if(b == NULL)
, but it dosen't work.
Or it's really not necessary to do the check? however I can hardly believe it...
PS: I only want to know whether the "Reference" itself could be NULL here. Whether the content of class B is null isn't important.
nullptr
keyword? It's a C++/CLI keyword, but maybe it works also with Managed C++. msdn.microsoft.com/en-us/library/4ex65770.aspx – Chaunce__gc
keyword, MEC++ doesn't have thegcnew
keyword, andpublic:
isn't capitalized in any flavor of C++ I've ever seen. – Lindsay