Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

How to overload * and -> operator


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 lride   Members   -  Reputation: 625

Like
0Likes
Like

Posted 10 January 2013 - 03:15 PM

I'm writing a handle for a  class. How can I overload * and -> operator?

I can't find one on Google


An invisible text.

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 6773

Like
1Likes
Like

Posted 10 January 2013 - 03:26 PM

struct FooPtr {
  Foo * data;

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


#3 frob   Moderators   -  Reputation: 8501

Like
1Likes
Like

Posted 10 January 2013 - 03:27 PM

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.



#4 Nanook   Members   -  Reputation: 337

Like
0Likes
Like

Posted 10 January 2013 - 10:08 PM

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



#5 lride   Members   -  Reputation: 625

Like
0Likes
Like

Posted 10 January 2013 - 10:26 PM

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

 

 

I'm writing a handle for a  class.


An invisible text.

#6 Nanook   Members   -  Reputation: 337

Like
0Likes
Like

Posted 11 January 2013 - 07:53 AM

Oh right.. I'm on painkillers after back surgery :P






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS