?
Solved

Overload operator ?

Posted on 1998-11-24
5
Medium Priority
?
238 Views
Last Modified: 2010-04-01
How to overload "->", "->*" operator ? (UNIX g++)
0
Comment
Question by:daohailam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 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