Possible Duplicates:
What is the difference between the dot (.) operator and -> in C++?
What is the arrow operator (->) synonym for in C++?
The header says it all.
What does -> mean in C++?
An Arrow operator in C/C++ allows to access elements in Structures and Unions. It is used with a pointer variable pointing to a structure or union.
It means "Give me the value of the thing pointed at the address stored at ptr ". In this example, ptr is pointing to a list item so ptr->next returns the value of the object's next property. Follow this answer to receive notifications.
C++ Relational Operators Here, > is a relational operator. It checks if a is greater than b or not. If the relation is true, it returns 1 whereas if the relation is false, it returns 0.
The 'this' pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. 'this' pointer is not available in static member functions as static member functions can be called without any object (with class name).
It's to access a member function or member variable of an object through a pointer, as opposed to a regular variable or reference.
For example: with a regular variable or reference, you use the .
operator to access member functions or member variables.
std::string s = "abc"; std::cout << s.length() << std::endl;
But if you're working with a pointer, you need to use the ->
operator:
std::string* s = new std::string("abc"); std::cout << s->length() << std::endl;
It can also be overloaded to perform a specific function for a certain object type. Smart pointers like shared_ptr
and unique_ptr
, as well as STL container iterators, overload this operator to mimic native pointer semantics.
For example:
std::map<int, int>::iterator it = mymap.begin(), end = mymap.end(); for (; it != end; ++it) std::cout << it->first << std::endl;
a->b
means (*a).b
.
If a
is a pointer, a->b
is the member b
of which a
points to.
a
can also be a pointer like object (like a vector<bool>
's stub) override the operators.
(if you don't know what a pointer is, you have another question)
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