Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

How to overload * and -> operator

4: Adsense

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   

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

#2 SiCrane   Moderators   

11761
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   

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


Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.


#4 Nanook   Members   

534
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   

663
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   

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