using enum says invalid conversion from 'int' to 'type'

后端 未结 4 1663
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 02:51

In my class I defined an enum like this:

class myClass 
{
 public:
    enum access {
      forL,
      forM,
      forA
    };
    typedef access AccessType;
            


        
4条回答
  •  情深已故
    2021-02-05 03:37

    You can't do an implicit cast from int -> enum, since at compile time there is no way to know that the cast is valid.

    You can do implicit casts the other way, so you could (if you wanted to) do:

    int foo = forL;
    

提交回复
热议问题