4

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.

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

oh no !! I am using MSVC 15.0.30729.1 and no idea how to check its c++11 features. I think it doesn't have thats why causing error.
0

Regarding the question about usage of C++11 in enum class definition, in code that describes HolePixelValueWrapper you are trying to initialize class member Value just in the same place where you declare it and it's not possible (not in C++11), only static class member are allowed to be initilaized like that. Remove = 0 and it will be OK.

If you want to keep initializing Value to zero, you can just make your constructor's parameter to have value by default, like that (of course if it's not breaking your design):

HolePixelValueWrapper(const T value = 0) : Value(value){}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.