Solved

Overload operator ?

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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 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.

733 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