hi,
I create a pointer, but the content of this pointer is nill. why this happen?
==========================================
MobileNode* M;
==========================================
MobileNode is a class.
When you declare a pointer it is uninitialized. To create an object you need to do it with new.
Anyway in modern C++ you should not use raw pointers at all. If you have to use pointers use the modern smart pointers: https://mbevin.wordpress.com/2012/11/18/smart-pointers/
int main() {
MobileNode* fubar = nullptr; // explicitly initialized null pointer
NodeLocation( fubar ); // Assume that the function can handle null pointer
MobileNode bar;
fubar = &bar; // fubar now points to an automatic object
NodeLocation( fubar );
fubar = new MobileNode; // fubar now points to dynamic object
NodeLocation( fubar );
delete fubar; // must deallocate the dynamic object explicitly
// bar deallocates automatically at end of function
}