Why cannot .(dot) be overloaded but -> can?


Here is the fundamental reason:

struct CMyClass
{
	void f(){}
};
void test()
{
	CMyClass a;
	a.f();
}

For the variable a, you do ‘a.’ but you are not allowed to do ‘a->’.
In another word, ‘a->’ is available, and ‘a.’ is already occupied.
If c++ allowed dot to be overloaded, much confusion would occur, because it’s already occupied.
Here is one example of the confusions: http://www2.research.att.com/~bs/bs_faq2.html

Advertisements
Comments are closed.
%d bloggers like this: