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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:36:11+00:00 2026-05-31T03:36:11+00:00

This code generates C2248 : ‘A::B::ExceptionB’ : cannot access private class declared in ‘class

  • 0

This code generates C2248 : 'A::B::ExceptionB' : cannot access private class declared in 'class A::B' in VS2008.

#include <iostream>

class A
{
    class ExceptionA{};

    class B
    {
        class ExceptionB{};
        public:
        B();
    };

    public:
    A(int);

};

A::B::B()
{
    throw ExceptionB();
}

A::A(int i)
{
    i % 2 ? throw ExceptionA() : throw A::B::ExceptionB();      //  C2248 !!
}

int main()
{
    try
    {
        A a(3);
    }
    catch( A::ExceptionA& )
    {
        std::cout << "A::ExceptionA" << std::endl;
    }
    catch( A::B::ExceptionB& )
    {
        std::cout << "A::B::ExceptionB" << std::endl;
    }
}

Of course, If I make the class ExceptionB{} public in B, the code compiles.

But I don’t understand why the compiler does’t complain about the 2 catch clauses in main(), as A::ExceptionA is a private class in A and A::B::ExceptionB is a private class in A::B.

  • 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-31T03:36:12+00:00Added an answer on May 31, 2026 at 3:36 am

    The question is worded a bit strangely, so I’m assuming that you’re asking why

    i % 2 ? throw ExceptionA() : throw A::B::ExceptionB();
    

    does not compile, while

    catch( A::ExceptionA& )
    catch( A::B::ExceptionB& )
    

    does.

    If you take a look at a copy of your handy dandy C++ standard (Chapter 11, paragraph 4), it says the following:

    It should be noted that it is access to members and base classes that is controlled, not their visibility.
    Names of members are still visible, and implicit conversions to base classes are still considered, when those
    members and base classes are inaccessible.

    The difference then in the above is that in the first case, you are trying to call a member of A::ExceptionA or A::B::ExceptionB — the constructors for the exception. But in the catch statement, you’re not accessing a member of any of those; you’re only accessing the type name.


    That said, I still believe this is a bug in MSVC++. The standard also says, in chapter 15.6 paragraph 1:

    If the exception-declaration in a catch clause has class type, and the function in which the catch clause occurs does not have access to the destructor of that class, the program is ill-formed.

    which your sample seems to violate, yet MSVC++ is accepting it without complaint.

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

Sidebar

Related Questions

This code generates a pair of public/private keys: KeyPairGenerator keyGen = KeyPairGenerator.getInstance(RSA); keyGen.initialize(1024); KeyPair
I have this sample code which generates the following warning (VS2008 compiler with SP1):
This code generates two compile time errors: private void DoSomething() { List<List<Foo>> myFoos =
This code generates Low memory warning because background 5 thread is almostly loading images
Ok, this situation is a little weird but anyway. This PHP code generates several
I have this code (an example that PHP generates for me)... <select id=outsideBlue3> <option
I have code that generates this error: ** Message: pygobject_register_sinkfunc is deprecated (GstObject) Traceback
I have some LINQ code that generates a list of strings, like this: var
I have some C# code that generates google maps. This codes looks at all
This code generates a compiler error that the member is already defined with the

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.