Solved

Overload operator ?

Posted on 1998-11-24
5
233 Views
Last Modified: 2010-04-01
How to overload "->", "->*" operator ? (UNIX g++)
0
Comment
Question by:daohailam
5 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1178605
Um, the same way you do with any other operator. :-)

Do you know anything about operator overloading?
0
 
LVL 5

Author Comment

by:daohailam
ID: 1178606
Edited text of question
0
 
LVL 5

Accepted Solution

by:
yonat earned 150 total points
ID: 1178607
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
 
LVL 5

Author Comment

by:daohailam
ID: 1178608
this is my case:

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

thanks !
0
 

Expert Comment

by:xje
ID: 1178609
The operator "->*" can implemented the same as "->"
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question