Difference between class.function() and class->function()

What is it

Last edited on
You could probably look at documentation

but here is my understanding of it

1
2
3
4
5
6
7
SomeClass *one = new one( someparameter ); // stored in a pointer
SomeClass two = one( someparameter ); // stored as is

// how to call them
one->function();
(*one).function();
two.function();


so I think that -> is just a short version for dereferencing from a pointer to a class.
I would look up documentation but I don't even know what to search to find it. Also I don't think that's right, no disrespect
Last edited on
For builtin pointers x->y is equivalent to (*x).y. Classes are free to overload either dereference or pointer member selection operators, but following the rule of least surprise they should work the same. For example look at the unique_ptr class.
Topic archived. No new replies allowed.