请教大大,一个C++编译错误,不知道咋回事

silwoods 2010-01-01 06:43:42
想做个数组队列,代码如下,在编译到定义队列
ACT_QUEUE g_que(0);
ACT_QUEUE z_que(1);
ACT_QUEUE c_que(2);

报错:
错误:expected identifier before numeric constant
错误:expected ‘,’ or ‘...’ before numeric constant
错误:expected identifier before numeric constant
错误:expected ‘,’ or ‘...’ before numeric constant
错误:expected identifier before numeric constant
错误:expected ‘,’ or ‘...’ before numeric constant

如果直接定义,不加参数,像这样,则不报这个错。
ACT_QUEUE g_que;
ACT_QUEUE z_que;
ACT_QUEUE c_que;


class QUE_ELEMENT
{
public:
int gz_flag;
int level;
int roleno;
double liliang;

vector < double > cg_liliang;

QUE_ELEMENT(int v_gz_flag)
{
gz_flag = v_gz_flag;
liliang = 0;

if (v_gz_flag == 1)
cg_liliang.resize(3,0);
};


QUE_ELEMENT & operator = (QUE_ELEMENT & vq);

};

class ACT_QUEUE
{
public:
vector < QUE_ELEMENT > _que;
int head;
int tail;

boost::mutex q_mutex;

ACT_QUEUE(int v_gz_flag)
{
_que.resize(LX_ACT_QUE_LEN,QUE_ELEMENT(v_gz_flag));
head = tail = 0;
};

void init();
bool push( const QUE_ELEMENT & vq);
bool pop();
int head_num();
int tail_num();
bool front(QUE_ELEMENT & vq);
bool front_pop(QUE_ELEMENT & vq);
bool empty();
private:
};

class L_TMP
{
public:
ACT_QUEUE g_que(0);
ACT_QUEUE z_que(1);
ACT_QUEUE c_que(2);
};
...全文
238 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
silwoods 2010-01-02
  • 打赏
  • 举报
回复
谢谢各位兄弟哈,问题解决了
macrojj 2010-01-01
  • 打赏
  • 举报
回复
class L_TMP { public: ACT_QUEUE g_que(0); ACT_QUEUE z_que(1); ACT_QUEUE c_que(2); };



在类里面只能声明对象

不能定义对象
Contemplating 2010-01-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cattycat 的回复:]
在类L_TMP定义变量不能调用其构造函数,
class L_TMP
{
public:
  ACT_QUEUE g_que(0);
  ACT_QUEUE z_que(1);
  ACT_QUEUE c_que(2);
};
这么写不对,你在这个类的构造函数中才能构造这些。
[/Quote]
这个解释是非常正确的。你试试:

class L_TMP
{
public:
L_TMP()
{
ACT_QUEUE g_que(0);
ACT_QUEUE z_que(1);
ACT_QUEUE c_que(2);
}
};


楼主的做法是在声明成员变量。但成员变量时不能那样初始化的。
cattycat 2010-01-01
  • 打赏
  • 举报
回复
在类L_TMP定义变量不能调用其构造函数,
class L_TMP
{
public:
ACT_QUEUE g_que(0);
ACT_QUEUE z_que(1);
ACT_QUEUE c_que(2);
};
这么写不对,你在这个类的构造函数中才能构造这些。
stardust20 2010-01-01
  • 打赏
  • 举报
回复
ACT_QUEUE g_que=ACT_QUEUE(0);

64,660

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧