The standard says, "A member of a class T cannot use T as its name if the member is a static data member, a member function, a member type, a member template, an enumerator of an unscoped enumeration, a member of a member anonymous union. However, a non-static data member may use the name T as long as there are no user-declared constructors."
However if I create this class, it gives an compile error.
class G
{
int G;
};
I am using VS2013. Is it not allowed in Microsoft or ?
Data members include members that are declared with any of the fundamental types, as well as other types, including pointer, reference, array types, bit fields, and user-defined types.
Accessing data members and member functions: The data members and member functions of class can be accessed using the dot('.') operator with the object.
The variables which are declared in any class by using any fundamental data types (like int, char, float etc) or derived data type (like class, structure, pointer etc.) are known as Data Members. And the functions which are declared either in private section of public section are known as Member functions.
A data member may be of any type, including classes already defined, pointers to objects of any type, or even references to objects of any type. Data members may be private or public, but are usually held private so that values may only be changed at the discretion of the class function members.
If VC++ doesn't allow this, it's a bug.
However, this language "feature" is for the purpose of C compatibility, and Microsoft has decided not to emphasize C. For example, C99 features are unavailable as a rule until adopted by C++. You should never purposely declare such a member in C++.
(It's allowed in C simply by default: there are no restrictions on the naming of members, and all members are nonstatic data members.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With