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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:43:27+00:00 2026-06-13T01:43:27+00:00

Trying to compile the following code on different compilers gives me two different results:

  • 0

Trying to compile the following code on different compilers gives me two different results:

struct S{};
struct T{S S;};
int main(){}

As you can see, inside T, I have an object named the same as the previously defined class S.


On GCC 4.7.2, I get the following error pertaining to the S S; declaration inside T:

error: declaration of ‘S T::S’ [-fpermissive]
error: changes meaning of ‘S’ from ‘struct S’ [-fpermissive]

However, moving it outside of the class (or into main) works fine:

struct S{};
S S;
int main(){}

What exactly does it mean by the error it’s giving me?


In Visual Studio 2012, the whole thing compiles and runs without any errors. Pasting it into this Clang 3.0 compiler gives me no errors as well.

Which is right? Can I actually do this or not?

  • 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-13T01:43:29+00:00Added an answer on June 13, 2026 at 1:43 am

    gcc is correct, from [3.3.7 Class Scope]

    A name N used in a class S shall refer to the same declaration in its
    context and when re-evaluated in the completed scope of S. No
    diagnostic is required for a violation of this rule.

    However, note that no diagnostic is required, so all compilers are conforming.

    The reason is because of how class scope works. When you write S S; S is visible within the entire class and changes the meaning when you use S.

    struct S{};
    struct T{
        void foo()
        { 
            S myS; // Not possible anymore because S refers to local S
        }
        S S;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile the following program: #include<functional> #include<iostream> int main(int argc, char* argv[],
I'm trying to compile the following code under VC2010. struct CircValRange { double a,b;
When trying to compile the following code, I am getting a warning that line
I am trying to compile the following code and i am getting the error:
I am trying to compile my gcc code using the following make command .
I'm trying to compile some code which contains the following declaration, because I would
When trying to compile the following (simplified) code for multiple platforms, I found that
I'm trying to configure Android.mk to cross compile native code to support different chipset
Iam trying to compile a file of the following format by making a parser
I am trying to compile 2 classes in C++ with the following command: g++

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.