Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 829039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:49:13+00:00 2026-05-15T03:49:13+00:00

Wouldn’t it make sense if p->m was just syntactic sugar for (*p).m ? Essentially,

  • 0

Wouldn’t it make sense if p->m was just syntactic sugar for (*p).m? Essentially, every operator-> that I have ever written could have been implemented as follows:

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

Is there any case where I would want p->m to mean something else than (*p).m?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:49:14+00:00Added an answer on May 15, 2026 at 3:49 am

    operator->() has the bizarre distinction of implicitly being invoked repeatedly while the return type allows it. The clearest way to show this is with code:

    struct X {
        int foo;
    };
    
    struct Y {
        X x;
        X* operator->() { return &x; }
    };
    
    struct Z {
        Y y;
        Y& operator->() { return y; }
    };
    
    Z z;
    z->foo = 42;          // Works!  Calls both!
    

    I recall an occasion when this behaviour was necessary to enable an object to behave as a proxy for another object in a smart-pointer-like context, though I can’t remember the details. What I do remember is that I could only get the behaviour to work as I intended using the a->b syntax, by using this strange special case; I could not find a way to get (*a).b to work similarly.

    Not sure that this answers your question; really I’m saying, “Good question, but it’s even weirder than that!”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know it probably wouldn't make much sense to do it as usually it's
I wouldn't ask if i wasn't sure that i have 100% no idea why
Why wouldn't C++ allow something like that ? I need to have multiple priority
Wouldn't it be better to have a method in the viewmodel that returns the
Probably my coding isn't so good and some lines wouldn't make much sense or
I have an ajax submit that wouldn't run no matter what I tried. That
Wouldn't it be nice to just do a keystroke and have eclipse organize all
Why wouldn't MySQL have this feature? INSERT INTO abc (a) VALUES ('bla') ON DUPLICATE
Ordinarily I wouldn't just post an error message on SO, but after a Google
I have a problem: (I wouldn't be here otherwise ;) I am creating an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.