I get the following error:
Cube.cpp:10: error: expected initializer before ‘<<’ token
Here's the important parts of the header file:
#ifndef CUBE_H
#define CUBE_H
#include <cstdlib>
#include <QtCore/QtCore>
#include <iostream>
#define YELLOW 0
#define RED 1
#define GREEN 2
#define ORANGE 3
#define BLUE 4
#define WHITE 5
using namespace std;
class Cube {
public:
...
static QList<int> colorList;
...
};
#endif
Here's the line that gives the error:
QList<int> Cube::colorList << YELLOW << RED << GREEN << ORANGE << BLUE << WHITE;
You can't initialize an object with <<
. The =
that is usually there is not operator=()
-- it's a special syntax that is essentially the same as calling a constructor.
Something like this might work
QList<int> Cube::colorList = EmptyList() << YELLOW << RED << GREEN << ORANGE << BLUE << WHITE;
where EmptyList() is
QList<int> EmptyList()
{
QList<int> list;
return list;
}
and is a copy construction of a list, and barring some optimization, a copy of the list that is created.
That line is not a initialization/definition of QList Cube::colorList. It is invoking insertion operator on an object which is not yet defined namely (QList Cube::colorList).
I don't know QT and hence can't comment on how to really initialize this class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With