Discussion Locked

how Overload arrow -> operator

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi pal,
Is there any routine any of u have how to overload -> operator in C++ that it work just like . opertor, I ve to call member function of class with object like A->function() rather then A.function()- consider it simple object not a pointer for example
Class ABC
{
private:
int c;
public:
functio(){//there is some code }
operator -> {//how to oerload}
};
main()
{
ABC A;
//Actual way
A.functio();
//I want
//A->functio();
}
So pls send me a cmplete code my email address is sulzar@yahoo.com

3 replies

by wayne m.

I would strongly recommend against doing this. If you are working in the C++ world, you should expect to work with both pointers and references. Do not try to confuse the two!

The key difference between a pointer and a reference is the implied persistance. A pointer can take a NULL (or uninitialized) value, while a reference can not. If you overload the pointer operator, you have the potential for a reference to an unknown memory area.

Use pointers where necessary, expect others to understand them, and don't try to hide the fact that a pointer is being used.

This discussion is closed to new replies.