• Advertisement
Sign in to follow this  

How to overload * and -> operator

This topic is 1836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
struct FooPtr {
  Foo * data;

  Foo & operator*() { return *data; }
  Foo * operator->() { return data; }
};

Share this post


Link to post
Share on other sites

You overload them exactly the same way you would overload any other operator.  

 

A caveat with A::operator->() must be a nonstatic member function.  (This also applies to =, [], and () operators.)

 

The others can be either a nonstatic member function, or they can be a nonmember function with at least one parameter referencing the class.

Share this post


Link to post
Share on other sites

Why are you overloading them? If its not similar to what SiCrane has in his example you probably want named functions instead..

Share this post


Link to post
Share on other sites
Why are you overloading them? If its not similar to what SiCrane has in his example you probably want named functions instead..

 

 

[quote name='lride' timestamp='1357852538' post='5020018']
I'm writing a handle for a  class.
[/quote]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement