This question already has an answer here:
I have a simple class:
class B
{
public:
int getData() { return 3; }
};
then, I initialize a pointer to it with nullptr:
B *foo{ nullptr };
And then, trying to use it comes the surprise:
int t = foo->getData();
and t is now 3. How is that possible without constructing the class? Is it because getData() does not use "this"? That broke all my knowledge about pointers.
Is that expected behavior? I am working in Visual Studio 2013.
Aucun commentaire:
Enregistrer un commentaire