Let's say I have the following variable:
MyObject* obj = ...;
If this object has the field foo, there are two ways of accessing it:
obj->foo(*obj).fooAre there any differences between using one method over the other. Or is the first method just syntactic sugar for the second?
I was thinking maybe the first one could cause the copy constructor of the object to be called since it is now holding onto the value.
There is no difference when obj is a pointer.
If obj is an object of some class, obj->foo will call operator->() and (*obj).foo will call operator*(). You could in theory overload these to do totally different behavior, but that would be a very badly designed class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With