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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:59:19+00:00 2026-05-23T19:59:19+00:00

Example: // can’t forward declare with class Foo::Bar // actual class class Foo {

  • 0

Example:

// can't forward declare with class Foo::Bar

// actual class
class Foo
{
public:
    class Bar // or enum Bar
    {
    }
};

I accept that this is not allowed under the current C++ standards, but I couldn’t come up with a good reason of not allowing it though, especially with C++0x, we’re now able to forward declare enums. I would imagine an argument against it would be if we foward declare nested class which turns out to be private, it wouldn’t be allowed. But this wouldn’t be too different to say forward declaring a class in a namespace, and then declaring it a nested class of an outer class. The compiler would simply give an error (perhaps an error message along the line of previous declaration doesn’t match this declaration).

So why is it really not allowed then?

In other words (by James McNellis), “why is class Foo::Bar; without providing a definition for Foo or Bar not allowed?”

** Given that the C++ standards committee recognised the benefit of using forward declarations to reduce dependencies and compile time by introducing forward declaration of enums in C++0x, surely this is part of the same thing isn’t it?

  • 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-23T19:59:20+00:00Added an answer on May 23, 2026 at 7:59 pm

    The reason that it is not in the language is simply that nobody has come up with a good proposal on how to include it in the language. Features don’t include themselves, someone has to write it up and explain the advantages and that there are no (or very minor) disadvantages.

    The argument for not forward declaring enums (enum x;) was simply that the compiler cannot select the proper size for enum variables until it has seen how many values there are. This problem was solved by allowing you to decide for the compiler (enum x : int;). This has also been implemented and shown to work properly, before entering the standard.

    See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf

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

Sidebar

Related Questions

Can anyone post an example of Aspect-oriented programming (AOP) that is not logging? I've
For example can i have something like this: public static void SAMENAME (sameparameter n)
How do the timeouts work in WCF? I know for example that you can
Example: Can I make a NIB which represents an view hierarchy, and use this
For example can I have class Dog { int legs; Bone chewy; Bone squeeky;
The spark panel component for example can be written like this <Panel title=Skinny> <child
This is a novice question. Hopefully this example can educate myself and others As
This is a novice question. Hopefully this example can educate myself and others As
I want to check that I have permissions on a RegistryKey for example can
Is this Possible that write a Socket by C# in ASP.net ? for Example

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.