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 8635789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:03:46+00:00 2026-06-12T10:03:46+00:00

I was trying to implement a smart pointer class similar to the standard library

  • 0

I was trying to implement a smart pointer class similar to the standard library auto_ptr and accordingly I had to overload the -> operator for the same. Here is my code

template <typename T>
class SmartPtr
{

   T * operator -> ()
  {
    return _pAct;
  }

 private:
 T * _pAct;
};

Rest of the implementation is not shown so as to avoid diversion from my query.

Now I create a SmartPtr of class A and call a method Show() present in A on it :

SmartPtr smPtr(new A);
smPtr->Show();

Here is my query(don’t know if its valid also)

Since SmartPtr::operator->() return A*, the call to show should translate to (A*)Show. Why it translates to (A*)->Show() ?

or in other words how does smPtr->Show() mean call Show() on whatever smPtr->() operator returns ?

  • 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-06-12T10:03:47+00:00Added an answer on June 12, 2026 at 10:03 am

    Because operator -> applies sequentially until it can’t be applied any more.

    13.5.6 Class member access [over.ref]

    1) operator-> shall be a non-static member function taking no
    parameters. It implements class member access using ->
    postfix-expression -> id-expression
    An expression x->m is interpreted
    as (x.operator->())->m for a class object x of type T if
    T::operator->() exists and if the operator is selected as the best
    match function by the overload resolution mechanism (13.3).
    (emphasis mine)

    Which means, in your case, it translates to:

    smPtr.operator->()->Show();
              |           |
          returns A*   call Show on the A*
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm trying to implement smart pointers in my code. I've created a class to
Im playing with my smart pointer class and I want to implement ++ and
Trying to implement a UITableView of names similar to the built-in Contacts iPhone app
I'm trying to implement line thickness as denoted here: start = line start =
I'm trying to implement my own list class but am having trouble reversing just
I am trying to use Test Driven Development to implement my signal processing library.
I am trying to implement left array rotation using the method described here: http://www.cs.bell-labs.com/cm/cs/pearls/s02b.pdf
Newbie programmer here trying to implement quicksort, yet it won't work. I've looked at
I'm trying to write a smart pointer wrapper (contains a boost shared_ptr or scoped_ptr

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.