0

I'd like to ask if by only using operator overloading is there a way to update a class member before accessing it. For example, I've got this class

class DictionaryWord
{
    string      Word;
    unsigned    Size;
    unsigned    Score;
};

and I want whenever I do objDictionaryWord->Size to get Word.size()

P.S. Also, I'm just starting to learn C++, if you know of some excelent tutorials for beginners that explain operator overloading please share them.

  • Welcome to Stack Overflow. Please take the time to read [The Tour](http://stackoverflow.com/tour) and refer to the material from the [Help Center](http://stackoverflow.com/help/asking) what and how you can ask here. – πάντα ῥεῖ Dec 26 '16 at 14:56
  • @πάνταῥεῖ member "Word" will change from time to time (let's say I'm going to make it public and change it directly). Right now I'm poking around the language and I want to know what's it capable of, so I'm really interested only in operator overloading (and hope that by seeing some code written by C++ gurus I'll be able to better understand this concept) – Dave Michael Dec 26 '16 at 15:04
  • Write a function to do that: `unsigned Size() { return word.size(); }` – πάντα ῥεῖ Dec 26 '16 at 15:06
  • There's no way with operator overloading. – πάντα ῥεῖ Dec 26 '16 at 15:14
  • @πάνταῥεῖ I'm only interested in doing it with operator overloading. I wouldn't have asked if I wanted it otherwise. So far I've learned that "." (member access operator isn't overloadable, but "->" and "->*" are, yet I'm having issues overloading them - don't know where to start) – Dave Michael Dec 26 '16 at 15:14
  • Refer to this question: http://stackoverflow.com/questions/4421706/operator-overloading – πάντα ῥεῖ Dec 26 '16 at 15:15
  • @πάνταῥεῖ Also, is there a way to know to which member is the -> operator pointing to? – Dave Michael Dec 26 '16 at 15:15
  • @πάνταῥεῖ Ok, thanks for chatting with me :) – Dave Michael Dec 26 '16 at 15:19

0 Answers0