so I learn C ++ and I just found out about dynamically allocated memory for a class. there is something that makes me feel weird.
int main()
{
person* pOne = new person("mike", 35);
cout << pOne << " " << pOne->getName() << endl;
person pTwo = { "dave", 30 };
cout << pTwo.getName() << endl;
return 0;
}
I think that when we want to call the getName () function in pOne, we should do it like this *pOne->getName()because pOne holds the memory cell, not the person object itself. but if I do this, I will get a compiler error.
I do this with pTwoone that is not dynamically allocated, and it works like I tought.
so, can someone explain the logic not to use "*" when trying to call a function?
source
share