Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Overload operator ?

How to overload "->", "->*" operator ? (UNIX g++)
0
daohailam
Asked:
daohailam
1 Solution
 
thresher_sharkCommented:
Um, the same way you do with any other operator. :-)

Do you know anything about operator overloading?
0
 
daohailamAuthor Commented:
Edited text of question
0
 
yonatCommented:
You can't overload the "->*" operator (and the ".*" operator).
To overload the "->" operator of class X, you write:

class X
{
public:
    X* operator->() {/* your code here */}
};

For examples, see my smart pointer classes at http://www.kinetica.com/home/yon/4dev/ .
0
 
daohailamAuthor Commented:
this is my case:

template<class T>
class foo
{
private:
      T* t;
public:
      T* operator ->()
      {
            return( t );
      }
};

thanks !
0
 
xjeCommented:
The operator "->*" can implemented the same as "->"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now