1

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?

quamrana
  • 37,849
  • 12
  • 53
  • 71
user692601
  • 107
  • 1
  • 3
  • 12

1 Answers1

8

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.

AVH
  • 11,349
  • 4
  • 34
  • 43
  • 1
    (An commonly useful alternative is to declare the `enum`s just before the `class`, in the same `namespace`, but which is better depends on whether the simplified concise usage reintroduces the risk of clashes with other symbols in that namespace, and the documentary value of the class-name prefix). – Tony Delroy Apr 05 '11 at 10:30