I know, that C++ has operators, that i shouldn’t overload.
operator ‘.’ is one of these operators that i can’t overload.
but, for best knowledge, does this overloading is bad?
I think, that it is really bad.
But i don’t need to know, if i have object or pointer to object.
However, this is funny and dangerous
class A {
public:
get_int(){ return a }
A(){ a=1 }
operator A*(){ return this }
private: int a;
};
int main(){
A a;
A* c = a;
//here, c->get_int() will return 1
}
You’d need to overload the indirection operator
->to allow universalx->foo()syntax, irrespective of whetherxis a pointer or not:Usage:
Example: