What to do with overload arguments

Question:
Which arguments do you receive when you overload . and -> , and what do you do with the arguments? I know that for overloading [] you receive the index. How about . and -> ?

Answer:
First, the . operator cannot be overloaded. If it could be, there would be no way to access members of the objectdirectly.

Here are the rules for operator -> :

  1. Operator -> must be defined as a member of a class.
  2. The operator takes a second argument but the type is unspecified.
  3. The return value must be a type for which operator -> is meaningful.

Here is an example:

struct X{   Y * operator ->() { return yPtr_; }   struct Y { void foo (); }   Y * pPtr;}X x; x->foo () ; // calls X::Y::foo
The operand to operator -> (in this case foo) is applied to its return value. If the return value is something for which -> does not make sense, that is an error.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a