I know this is a very basic question, but after a few google searches and clicking on multiple links, I still couldn’t find an answer.
My question is what is the difference between the ” . ” and the ” -> ” in function calling in C++ language?
For example, I have a program with 2 different data structures.
Semaphore aaa;
List bbb;
To use a function on semaphore, I have to do aaa.P();
but on List, I have to do List->append(object);
I don’t quite understand why Semaphore uses .P() whereas List uses ->append()
when semaphore is just a data structure containing an integer and a list.
Use the
.operator when you’re accessing members using the object itself, or a reference to the object.Use the
->operator when you’re accessing a member via a pointer to the object. Continuing the above example