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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:27:44+00:00 2026-05-24T01:27:44+00:00

I have a Visual Studio 2008 C++ program where I have my own stream

  • 0

I have a Visual Studio 2008 C++ program where I have my own stream implementation. Something like this:

class Foo : public std::ostream
{
public:
    Foo( int a ) : std::ostream( &buf_ ) { };
    Foo( boost::shared_ptr< int > a ) : std::ostream( &buf_ ) { };
private:
    std::filebuf buf_;
};

class Bar
{
public:
    Foo GetFoo() { return Foo( 1 ); };
    Foo GetFoo2() { return Foo( boost::shared_ptr< int >( new int( 1 ) ) ); };
};

The intended usage is like this:

Bar b;
Foo f = b.GetFoo(); // works fine
Foo f2 = b.GetFoo2(); // compiler error

Unfortunately, this gives me a compiler error about the basic_ios copy constructor.

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

Why is the first Foo( int ) constructor okay with the compiler, but the one involving a boost::shared_ptr is not?

Thanks,
PaulH

  • 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-24T01:27:45+00:00Added an answer on May 24, 2026 at 1:27 am

    Your Foo class is inheriting from a non-copyable class, yet you are not implementing the copy constructor. You are bound to get into trouble when you pass instances of Foo by value, as you do in the getter functions.

    The reason that GetFoo works might be that return-value optimization is eliding the copy construction, but this doesn’t mean that you’re allowed to do this.

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

Sidebar

Related Questions

I have visual studio 2008. I have a written a small C program. I
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL
I'm using Visual Studio 2008. I have a DLL and a test program EXE.
Visual Studio C++ 2008 / GCC 4.4.2 I have written a program to run
I have Visual Studio 2008 and i installed and removed StrataFrame Framework. This framework
I have a Visual Studio 2008 C++ application where I would like to copy
I'm stuck and I need help. Anyway I have Visual Studio 2008 console program
Okay, this is getting stupid, I have Microsoft Visual Studio 2008, was working fine,
I have a program written in VB.Net with Visual Studio 2008. I have one
I have the following C++ program and ran it using Visual Studio 2008 on

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.