Home > Back-end >  Excuse me, how to extend enumerated types by means of inheritance?
Excuse me, how to extend enumerated types by means of inheritance?

Time:11-07

Maybe it's a problem description not clear, the following code:
 
The class GroupA
{
Enum T {
Student1=0,
Student2,
Student3,
}
};

The class GroupB
{
Enum T {
Student4=0,
Student5,
Student6,
}
};


Above GroupA and GroupB Student Numbers from 0 begin, how to realize a new class or enumeration, allow the Student1 Student6 numbered sequentially 0,1,2,3,4,5?

 
The class GroupAB: public GroupA, public GroupB
{
};

Directly inherited this number will not change, is there any possible way, guide, thank you.

CodePudding user response:

No,
No answers, is the problem wrong,
This is your confusion of problems and solutions,

CodePudding user response:

The code above 2 points. You
1. T is defined by the type enum, pay attention to this is the type, not variable, similar int, members can only is a variable or function in a class
2. Both enumeration class from zero beginning, how to distinguish Student1/Student4

CodePudding user response:

reference 1st floor taodm response:
,
No answers, is the problem wrong,
This is your confusion of problems and solutions,

No matter what way, as long as you can put together two enumeration, and renumbered,
As two of the students in the class, two class to synthesize a class, student id is redistributed,
If there is no theoretical support, normally this kind of problem how to deal with?
Thank you for your reply,

CodePudding user response:

Compile time, can't do,
The runtime, literally,
  • Related