Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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: 633

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: 9662

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: 22684

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 write about assorted stuff.


#4 Nanook   Members   -  Reputation: 505

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: 633

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: 505

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