Solved

Overload operator ?

Posted on 1998-11-24
5
231 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TTimer no longer functioning 7 85
how to convert c++ code to Android App 3 83
Best book to learn C++ 4 70
max float value 3 25
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now