Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why did C++03 allow data members with the same name as the class?

Between the C++98 standard and the C++03 standard, an interesting change was made:

struct S {
    int S;
};

This code is valid in C++03 and newer, but was ill-formed in C++98.
Specifically, [class.mem] paragraph 13 banned all data members from having the same name as the class in C++98, but this rule was relaxed so that if there is no user-declared constructor, you can have a non-static data member with the same name.

What is the motivation behind this?
What important use case is covered by this that would warrant revising the standard?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is from DR80. To paraphrase, static was there originally to conform with C but between the May ’96 and September ’96 working papers the standard was changed and static was removed. C++03 reverted that error from the language via the defect report.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading