L
L
LaFa7772014-08-14 19:59:22
Qt
LaFa777, 2014-08-14 19:59:22

Data array as class member?

Hi all. I am making a program in Qt 5.3.1 with the compiler included in the Microsoft Visual studio 2013 Express Desktop . The task arose to build a schedule into the program, I came to the conclusion that it would be more logical to implement it as an array of numbers, initially available as a member of the class, but there were problems with the implementation. The following class compiles under MinGW , but becomes broken when compiled with VS 2013 . (studio is required to compile for 64 bit architecture)

class C
{
  int x[4] = { 0, 1, 2, 3 };
public:
  C(){}
};

Studio error:
Error 1 error C2536: C::C::x: cannot specify an explicit initializer for arrays

Question: What is the best way to store such data in c++? Is there a compromise that would suit both VS 2013 and MinGW ? Perhaps the arrays built into the language are not the best solution for such a task and it is necessary to use Qt tools?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2014-08-14
@LaFa777

The compiler doesn't like initialization (assignment). Do it in the constructor. A std::vector is almost always as good as a regular array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question