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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:30:39+00:00 2026-05-27T04:30:39+00:00

What are the reasons behind that we can not declare and define a variable(property)

  • 0

What are the reasons behind that we can not declare and define a variable(property) inside a class with the same name of the class itself? For example this code is not right(at least in MS VC++):

class test{

public:
int test;

};
  • 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-27T04:30:39+00:00Added an answer on May 27, 2026 at 4:30 am

    Your code is legal, if MS VC++ says otherwise then it is wrong.

    In C++11, 9.2/16:

    In addition, if class T has a user-declared constructor (12.1), every
    non-static data member of class T shall have a name different from T.

    Your class does not have a user-declared constructor, and the data member you define is non-static, so it can be named test. If it were static, then 9.2/15 says it can’t be named test, but 9.2/15 says nothing about non-static data members.

    In C++03, it’s 9.2/13 and /13a, the rules are the same.

    If MS VC++ issues a warning, then that’s probably justified. The effect of your data member makes more sense to C programmers than to C++ programmers:

    struct test{
        void foo(test &a) {   // "test" is a type here
            struct test t;    // "test is not a type here, "struct test" is
            a = t;
        }
        int test;
    };
    
    struct test{
        int test;
        void foo(struct test &a) {   // now "test" is not a type here either
            struct test t;
            a = t;
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For reasons that only the developers can understand, Firefox will create and open .url
Any reasons why this can not be standard behavior of free() ? multiple pointers
For reasons that I would not like to discuss, our master database schema is
Take a look into source code . There could be valid reasons behind that,
I understand the concept and reasons behind using the using statement, and I use
For some convoluted reasons best left behind us, I require direct access the contents
For reasons that are irrelevant to this question I'll need to run several SQLite
What are possible reasons why NHibernate does not perform delete operation? public bool Delete(MyType
I understand the security reasons behind dis-allowing JS copying arbitrary text to the clipboard,
Is there a way that I can Programmatically set an Expires Header in code

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.