无法初始化静态QList? [英] Can't initialize static QList?

查看:207
本文介绍了无法初始化静态QList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下错误:

Cube.cpp:10:错误:'< code>

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

这里是给出错误的行:

QList<int> Cube::colorList << YELLOW << RED << GREEN << ORANGE << BLUE << WHITE;


推荐答案

$ c><< = 通常不存在 operator =() - 这是一种特殊的语法,调用构造函数。

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.

这样的工作可能起作用

QList<int> Cube::colorList = EmptyList() << YELLOW << RED << GREEN << ORANGE << BLUE << WHITE;

其中EmptyList()是

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.

这篇关于无法初始化静态QList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆