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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:43:17+00:00 2026-06-15T09:43:17+00:00

In this question it was discussed why exposing a private type with auto :

  • 0

In this question it was discussed why exposing a private type with auto:

#include <iostream>

using namespace std;

class Base {

  class PrivateClass {    
  public: 
    void bar() { cout << "PrivateClass" << endl; }
  };

public:

  PrivateClass foo() {
    PrivateClass a;
    return a;
  }

};

int main() {

  Base b;
  auto p = b.foo();
  p.bar();
  return 0;
}

is perfectly fine by the C++11 standard. What I still don’t get is how this idiom may be useful in a real application.
Are there problems where this idiom can be effectively used, or it should be considered as a “curious” side-effect of the keyword?

  • 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-15T09:43:18+00:00Added an answer on June 15, 2026 at 9:43 am

    It can be useful if the return type is unspecified. For example, the returned object from a call to std::bind, or formerly boost::bind, is not specified. It is some implementation-defined functor, but you can’t actually know its type without looking at implementation details. Before C++11’s auto keyword, you could use boost::function as a variable type for storing the result of bind, or you could pass the result of bind to a function which takes a template argument. With C++11, you can store the result object using auto.

    So, if a class has some internal type, it is not necessary to expose the actual type to a public API. A user of the class can simply use the auto keyword, and the API documentation can say the type is “unspecified”. This keeps the actual internal type a private implementation detail, which can often improve encapsulation.

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

Sidebar

Related Questions

As discussed in this question and everywhere else, Apple now requires apps to include
In this question the issue of using dates in data.table s was discussed. A
As discussed a bit in this question , I am using Apache mod_include with
I know this question has been discussed before, and I know this is such
I know this question might have already been discussed a thousands of times but
This is a question on C/C++ function definitions. The code discussed is the static
In this excellent SO question , differences between CTE and sub-queries were discussed. I
There are already several threads where this question is discussed, and I have already
Looked around, couldn't find this specific question discussed. Pretty sure the difference is negligible,
This problem is discussed in this question Android: Wrong item checked when filtering listview

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.