pointers - C++/CLI how do I tell if a handle isn't pointing to any object -


in normal c++ there pointers indicated null if not pointing object.

class* object1 = null; //null special value indicates                        //that pointer not pointing object.  if(object1  == null) {     cout << "the pointer not pointing object" << endl; } else {     cout << "the pointer pointing object" << endl; }  

how c++/cli handles? have found on internet. can tell me if im right this?

class^ object2 = nullptr; if(object2 == nullptr){     cout << "the pointer not pointing object" << endl; } else {     cout << "the pointer pointing object" << endl; } 

you should not use null in c++. opt nullptr.

consider this:

void some_function(some_class* test); void some_function(int test);  int main() {     some_function(null); } 

since humans interpret null pointer "type," programmer might expect first overload called. null defined integer 0 -- , compiler select second. isn't problem if understand what's happening, isn't intuitive.

in addition, 0 is valid memory address. in desktop programming don't allocate data address 0, valid in other environment. can check allocation @ 0?

to stop ambiguity, c++ features explicit nullptr. not integer, has own special type , cannot misinterpreted: pointer has strongly-typed empty value.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -