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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:43:01+00:00 2026-05-28T00:43:01+00:00

namespace A { class B { public: B(int); }; } namespace C { class

  • 0
namespace A
{
    class B
    {
    public:
        B(int);
    };
}

namespace C
{
    class D
    {
        static const ::A::B b;
    };
}

const ::A::B ::C::D::b(0);      // #1
// const ::A::B C::D::b(0);     // #2
// const ::A::B (::C::D::b)(0); // #3

Option #1 fails to compile. Now that I’ve thought about it for a while, I’m pretty sure the compiler considers the whitespace between “B” and “::C” insignificant, so it is trying to find a member “C” inside “B”. If that’s what’s happening, I need some way to convince the compiler that these are two separate qualified names.

Options #2 and #3 both seem to work in a very minimal test. #3 seems somewhat less vulnerable to name collisions since it’s more qualified. #3 is also somewhat easier for me to switch to. So I lean towards #3, but it looks weird.

Is there any strong reason to prefer one over the other? Can I expect both to work correctly on other compilers? Is there an even better solution than either one? And for that matter, am I correct about why #1 fails?

Probably unnecessary details

  • The code that inspired this question was output by a source code generator I wrote. The identifiers are derived from the generator’s input, so I’m concerned about name collisions, specifically unintentional shadowing between scopes, which the generator can’t detect. So, I wrote the generator to qualify every identifier as fully as possible.
  • I’m compiling on VC2010.
  • I’m intentionally not using C++0X features, as I want the code to be portable to certain older compilers.
  • The specific compiler error is “error C3083: ‘C’: the symbol to the left of a ‘::’ must be a type”
  • 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-28T00:43:02+00:00Added an answer on May 28, 2026 at 12:43 am

    I’m pretty sure the compiler considers the whitespace between “B” and “::C” insignificant, so it is trying to find a member “C” inside “B”

    That’s precisely correct.

    Is there any strong reason to prefer one over the other? Can I expect both to work correctly on other compilers?

    Option #3 looks fine to me (and is compliant); that is, if you’re really stuck with this rather silly-looking requirement. 🙂

    I use it myself to conclude a blog post on a very similar “issue”.

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

Sidebar

Related Questions

#include<iostream> using namespace std; class A { private: const int a=9; public: void display()
Example code: #include <cstdlib> #include <iostream> using namespace std; class A { public: A(int
using namespace std; class A { public: A() {} ~A() {} map<int, string*>& getMap()
#include <iostream> using namespace std; struct testarray{ int element; public: testarray(int a):element(a){} }; class
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
I've got 3 classes namespace ServerPart { public class Car { } public class
Suppose I've got the following program: namespace ReflectionTest { public class Example { private
Say I have some code like namespace Portal { public class Author { public
I need to build a class in this form namespace BestCompanyEver { public class
I have the following types and classes: namespace MVC.Models public class Page { public

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.