Home > Back-end >  Turn to the language problem
Turn to the language problem

Time:11-26

For a problem, see your writing template class in c + + program design language of enum can outside the class definition, is about this structure:

Template
Class C {
Public:
Enum E: int.
};

Template
Enum C : : E {a, b, c};

Under VS2017 run however, C3113, says do not allow the enum is template,
In addition, in the initializer ({a, b, c}), reported E2762, enumerator declared (please refer to the constant "C : : a ", ABC was featured a,


Template attached to this chapter 3 section experiment and expect different, crazy, solve, thank you,

CodePudding user response:

C3113 do not understand,
E2762 behind the will not because a E specifies: int, another behind is not specified, although is E, but are treated as two different types? The second place behind E also add: int a try?

CodePudding user response:

reference 1/f, drink A reply:
C3113 do not understand,
E2762 behind the will not because a E specifies: int, another behind is not specified, although is E, but are treated as two different types? The second place behind E also add: int a try?

Thanks, but no, plus: after int error list without any change

CodePudding user response:

Progress:
Downloaded DEVC++, try the code and modify according to the error message, the resulting can run the following code:

# include
using namespace std;
Template
Struct C {
Public:
Enum E: char {};//must be {}
};

Template
Enum C : : E: char {=123 a, b, c};//must have a char

Int main () {
C c;
C E1: : E=C B: :;
Cout<(int) e1;
}

And found that C struct must be used, if use the class will tell me ABC is private, don't know what to do,
Even realized template type enum members outside the class definition of the basic goals, forms are completely different, and the book
The same code is copied to the VS a bunch of errors, the difference of the compiler how can have such a big disagreement...
  • Related