enums declaration in class C++, problem getting to enum in class
I have problem with the declaration of enum in my class. I had tried to declare it on private, public, outside, in the main, nothing works. I need to call function in the class 开发者_运维技巧from outside and use the enums in the function here is my code.
class Algoritem {
public:
enum Optimization { W , A , D };
enum FenceType { OF , CC };
enum Eventopa { BR , OR };
algorithem* OptimalPatrol(double N, int K, double VS, double T, Optimization F,FenceType FT, Eventopa E, double Imax,double P);
};
When I need to call OptimalPatrol() I need to input the 3 enums. I can't redeclare them in the main, so how can I input my enums with variable from the main?
You have to specifiy which class the enums are defined in. So, e.g. call the function like this:
OptimalPatrol(N, K, VS, T, Algoritem::W, Algoritem::OF, Algoritem::BR, Imax, P);
That way, your compiler knows in which class to look for the enum declarations.
精彩评论