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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:57:07+00:00 2026-06-06T11:57:07+00:00

I am just trying to compile a bit bigger project using the Visual Studio

  • 0

I am just trying to compile a bit bigger project using the Visual Studio 2012 Release Candidate, C++. The project was/is compiled using the VS2010 now. (I am just greedy to get the C++11 things, so I tried. 🙂

Apart of things that I can explain by myself, the project uses the code like this:

ostringstream ostr;
ostr << "The " __FUNCTION__ "() failed to malloc(" << i << ").";
throw bad_alloc(ostr.str().c_str());

The compiler now complains

error C2248: 'std::bad_alloc::bad_alloc' : cannot access private member declared 
    in class 'std::bad_alloc'

… which is true. That version of constructor is now private.

What was the reason to make that version of constructor private? Is it recommended by C++11 standard not to use that constructor with the argument?

(I can imagine that if allocation failed, it may cause more problems to try to construct anything new. However, it is only my guess.)

Thanks,
Petr

  • 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-06T11:57:09+00:00Added an answer on June 6, 2026 at 11:57 am

    The C++11 Standard defines bad_alloc as such (18.6.2.1):

    class bad_alloc : public exception {
    public:
        bad_alloc() noexcept;
        bad_alloc(const bad_alloc&) noexcept;
        bad_alloc& operator=(const bad_alloc&) noexcept;
        virtual const char* what() const noexcept;
    };
    

    With no constructor that takes a string. A vendor providing such a constructor would make the code using it not portable, as other vendors are not obliged to provide it.

    The C++03 standard defines a similar set of constructors, so VS didn’t follow this part of the standard even before C++11. MS does try to make VS as standard compliant as possible, so they’ve probably just used the occasion (new VS, new standard) to fix an incompatibility.

    Edit: Now that I’ve seen VS2012’s code, it is also clear why the mentioned constructor is left private, instead of being completely removed: there seems to be only one use of that constructor, in the bad_array_new_length class. So bad_array_new_length is declared a friend in bad_alloc, and can therefore use that private constructor. This dependency could have been avoided if bad_array_new_length just stored the message in the pointer used by what(), but it’s not a lot of code anyway.

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

Sidebar

Related Questions

I'm trying to port a C++ project to iOS. It compiles just fine in
I'm trying to connect to MySQL using MATLAB R2009b 64 bit and the mysql.cpp
I'm trying to compile a bit of code that looks something like so: (examples
How do I compile 16-bit C code with GCC? I am trying to write
Just trying to compile some trivial Haskell, but its not finding the c runtimes,
I'm trying to get a simple program using JOGL to compile via the command
I'm a bit stuck here, basically I'm trying to compile Box2D as a static
Trying to compile a C++ kernel project with MinGW & NASM (formerly DJGPP &
I'm having a bit of trouble trying to compile Qt programs under Windows. I'm
I'm trying to load a mixed managed/native dll, which I compiled for 32 bit

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.