Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum error: 'enum' : missing tag name

I am trying to compile an application which is showing error in following line:

enum class HoleMaskPixelTypeEnum {HOLE, VALID, UNDETERMINED};

I haven't uses enum is such way along with class keyword. If I comment the keyword class then following error occur

error C2864: 'HolePixelValueWrapper<T>::Value' : only static const integral data members can be initialized within a class

which is in following code:

 template <typename T>
struct HolePixelValueWrapper
{
  HolePixelValueWrapper(const T value) : Value(value){}

  operator T()
  {
    return this->Value;
  }

  T Value = 0;//error here.
};

No idea to solve it.

like image 619
Tab Avatar asked Dec 20 '22 21:12

Tab


2 Answers

Scoped enumerations (enum class) and in-class initialisation of member variables are a fairly new language features (introduced in C++11); according to this table, the former needs Visual Studio 11.0 or later, and the latter is not yet supported.

If your compiler doesn't support scoped enumerations, then the only option is to remove class. You might consider scoping it inside a class or namespace, if you don't want to cause wider pollution.

If it doesn't support in-class initialisation, then you'll just have to do it the old-fashioned way in the constructor(s). However, there's no point using it here anyway, since the member is initialised by the only constructor. Just remove the = 0.

like image 110
Mike Seymour Avatar answered Dec 22 '22 11:12

Mike Seymour


enum class Blah is a C++11 feature. Are you compiling with a C++11 compiler?

like image 42
benjymous Avatar answered Dec 22 '22 11:12

benjymous