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

  • Home
  • SEARCH
  • 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 1898686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:47:48+00:00 2026-05-17T06:47:48+00:00

Possible Duplicate: Why does C have a distinction between -> and . ? What

  • 0

Possible Duplicate:
Why does C have a distinction between -> and . ?

What is the real reason for a programmer to have to differentiate between . and -> when accessing a member of an object?

void foo( Point &p ) {
    p.x ;
    p->y; // syntax error
} 

void foo( Point *p ) {
    p.x ; // syntax error
    p->y;
} 

I mean, one way or another, they both refer to an object, p.

  • Why do I have to bother checking every time what p is ? Can’t the compiler understand ?

  • Why haven’t they allowed it to accept . syntax for both? That would be fine for stack objects too.

And if it is due to C-tradition,

  • Why don’t they allow both . and -> accessors?

For more than 15 years, I have always humbly considered the compiler errors as being my fault !

  • 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-17T06:47:49+00:00Added an answer on May 17, 2026 at 6:47 am

    Because p->d actually means (*p).d. It does a dereference and then a member access. References behave like objects thus they don’t need dereferencing (they are also a C++ feature, while pointer are inherited from C); it has been kept that way for backwards compatibility.

    C++ is full of inconsistencies like this, but there’s usually no better choice to add new features and keep old code working. Rewriting the old code is not an option.

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

Sidebar

Related Questions

Possible Duplicate: Why does C have a distinction between -> and . ? Lets
Possible Duplicate: Does Java guarantee that Object.getClass() == Object.getClass()? If I have a class
Possible Duplicate: How does dereferencing of a function pointer happen? If we have void
Possible Duplicate: What does it mean to have an undefined reference to a static
Possible Duplicate: Why does this integer division yield 0? I have a C header
Possible Duplicate: How does foreach work when looping through function results? If I have
Possible Duplicate: Why does Mac's $find not have the option -printf? Not sure what
Possible Duplicate: Why does the background of TextView change it's size? I have a
Possible Duplicate: Reference - What does this symbol mean in PHP? I have a
Possible Duplicates: C++: ptr->hello(); /* VERSUS */ (*ptr).hello(); Why does C have a distinction

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.