Home > Back-end >  Classes are defined in the enumeration members for the data
Classes are defined in the enumeration members for the data

Time:10-04

The class DataType {
.
Private:
Enum type {type_int, type_char type_float};
The union {
Int num_int;
Char num_char;
Float num_float;
};
};

Defines the private data members in the class type, enumeration type but compile error
[error] enum DataType: : type 'is not a non - static data member of' DataType '

According to put the enumeration name later in the book, instead of enum {type_int type_char, type_float} type can
What is the difference between before and after the enumeration name, please?

CodePudding user response:

Front is the representative of a type name

CodePudding user response:

No problem, VS2015 c + + environment
 class DataType 
{
Private:
Enum type {type_in, type_char type_float};
The union {
Int num_int;
Char num_char;
Float num_float;
};
};
Int main ()
{
return 0;
}

CodePudding user response:

Estimation is he types as a instance,

refer to the second floor MianHou response:
no problem ah, VS2015 c + + environment
 class DataType 
{
Private:
Enum type {type_in, type_char type_float};
The union {
Int num_int;
Char num_char;
Float num_float;
};
};
Int main ()
{
return 0;
}

CodePudding user response:

Class A {
Enum type {... };
}
On behalf of a type, he is must to use the
A: : type o=...
==========
Class A {
Enum {... } type;
Is a representative of the anonymous enumeration, the type is a field
Can use the
A, A.
A.t ype access,,,

CodePudding user response:

references in 4th floor, the truth is more important than right or wrong response:
class A {
Enum type {... };
}
On behalf of a type, he is must to use the
A: : type o=...
==========
Class A {
Enum {... } type;
Is a representative of the anonymous enumeration, the type is a field
Can use the
A, A.
A.t ype access,,,

I see thanks!

CodePudding user response:

reference 3 floor truth is right or wrong response:
estimation is he types as a instance,

Quote: refer to the second floor MianHou response:

No problem, VS2015 c + + environment
 class DataType 
{
Private:
Enum type {type_in, type_char type_float};
The union {
Int num_int;
Char num_char;
Float num_float;
};
};
Int main ()
{
return 0;
}

For at first thought that definition is also behind the enumeration name, confused, now I see, thank you!
  • Related