The dot (.) operator is used for direct member selection via object name. In other words, it is used to access the child object.
x = 20, y = 1
Is dot (.) actually an Operator?
Yes, dot (.) is actually an operator in C/C++ which is used for direct member selection via object name. It has the highest precedence in Operator Precedence and Associativity Chart after the Brackets.
Is there any other Operator like dot(.) operator?
Yes. There is another such operator (->). It is called as “Indirect member selection” operator and it has precedence just lower to dot (.) operator. It is used to access the members indirectly with the help of pointers.
Can dot (.) operator be overloaded?
No, Dot (.) operator can’t be overloaded. Doing so will cause an error.
prog.cpp:11:20: error: expected type-specifier before '.' token cantover& operator.() ^ prog.cpp:11:12: error: expected ';' at end of member declaration cantover& operator.() ^ prog.cpp:11:20: error: expected unqualified-id before '.' token cantover& operator.() ^ prog.cpp: In function 'void g(X&)': prog.cpp:15:7: error: 'void X::fun()' is private void fun(); ^ prog.cpp:19:8: error: within this context x.fun(); // X::fun or cantover::fun or error? ^
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- map::operator in C++ STL
- set operator= in C++ STL
- map operator= in C++ STL
- new vs operator new in C++
- unordered_set operator!= in C++ STL
- std::basic_string::operator in C++
- unordered_set == operator in C++ STL
- multimap::operator= in C++ STL
- array::operator[ ] in C++ STL
- deque::operator= and deque::operator in C++ STL
- vector::operator= and vector::operator[ ] in C++ STL
- list::operator= in C++ STL
- unordered_map operator= in C++ STL
- multiset::operator= in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.