我的队列有问题。 [英] Having trouble with my queue.

查看:70
本文介绍了我的队列有问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我似乎无法使用STL队列建立对象队列。我正在尝试

来组建一个小事件管理器,我只是想在某个地方存储事件。

EventManager的方法定义已被评论为

调试期间没有任何内容,但标题看起来像


类活动

{

私人:

对象*收件人;

int eventID;

public:

Event(Object * r,int e)

{recipient = r; eventID = e;}

~Event(){cout<< 事件已删除。\ n;}}

对象* get_recipient(){返回收件人;}

int get_id(){return eventID;}

};


class EventManager

{

private:

queue< Event> ; event_queue;

// void start();

// void pop();

public:

// void push(事件e);

// int num_in_queue(){return 0;} // event_queue.size();}

};


当我尝试使用CodeWarrior进行编译时,我收到40条错误消息,而不是
标记我的任何代码。我已将它们复制到下面,并且它的错误信息都是

了。


我哪里出错了?


错误:函数调用''__ct()''不匹配

''Event :: Event(Object *,int)''

''事件::事件(const事件&)''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义的标识符''erase''

(实例化:''deque<事件,分配器<事件>>'')

MSLHeaders ++。h line 19#包括< MSLHeaders.PPC.mch>


错误:标识符''insert''relaclalared

(实例化:''deque<事件,分配器<事件> ;>'')

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:标识符''insert''重新声明

(实例化:''deque<事件,分配器<事件>>'')

MSLHeaders ++。第19行#include< MSLHeaders.PPC.mch>


错误:标识符''insert''重新声明

(实例化:'' deque<事件,分配器<事件>>'')

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:标识符''insert''重新声明

(实例化:''deque<事件,分配器<事件>>'')

MSLHeaders ++。h line 19 #include< MSLHeaders.PPC.mch>


错误:未定义标识符''pop_front''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:表达式语法错误

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''擦除''

MSLHeaders ++。h第19行#include& LT; MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''erase''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义的标识符''erase''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''erase''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:表达式语法错误

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:非功能调用

MSLHeaders ++。第19行#include< MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include < MSLHeaders.PPC.mch>


错误:未定义标识符''pop_front''
(实例化:''deque<事件,分配器<事件> >'')

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:函数调用''__ct()' '不匹配

''Event :: Event(Object *,int)''

''Event :: Event(const Event&)''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''erase''

(实例化:''deque<事件,分配器<事件>>'')

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:标识符''insert''relayclared

(实例化:''deque<事件,allocato r< Event>>'')

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:标识符''插入''重新申报

(实例化:''deque<事件,分配器<事件>>'')
MSLHeaders ++。h line 19 #include< MSLHeaders.PPC。 mch>


错误:标识符''insert''relayclared

(实例化:''deque<事件,分配器<事件>>'')

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:标识符''insert''relaclalared

(实例化:''deque<事件,分配器<事件>>'')

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''pop_front''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:非功能呼叫

MSLHeaders ++。h line 19 #i nclude< MSLHeaders.PPC.mch>


错误:表达式语法错误

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''擦除''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>

错误:调用非函数

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''erase''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义标识符''erase''

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include< ; MSLHeaders.PPC.mch>


错误:未定义标识符''擦除'

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:表达式语法错误

MSLHeaders ++ .h第19行#include< MSLHeaders.PPC.mch>


错误:调用非函数

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:调用非功能性

MSLHeaders ++。h第19行#include< MSLHeaders.PPC.mch>


错误:未定义的标识符''pop_front''

(实例化:''deque<事件,分配器<事件>>'')

MSLHeaders ++。第19行#include< MSLHeaders.PPC.mch>

-

"然后他们把主的方舟放在车上;随着盒子

包含金色老鼠和痔疮的图像。

- 1 Samuel 6:11


I can''t seem to make a queue of objects, using the STL queue. I''m trying
to make a little event manager, and I just want someplace to store events.
The method definitions for EventManager have been commented away to
nothing during debugging, but the headers look like

class Event
{
private:
Object* recipient;
int eventID;
public:
Event(Object* r, int e)
{recipient = r; eventID = e;}
~Event() {cout << "Event deleted.\n";}
Object* get_recipient() {return recipient;}
int get_id() {return eventID;}
};

class EventManager
{
private:
queue<Event> event_queue;
// void start();
// void pop();
public:
// void push(Event e);
// int num_in_queue() {return 0;}// event_queue.size();}
};

When I try to compile with CodeWarrior I get 40 error messages that don''t
flag any of my code. I''ve copied them below, and it''s error messages all
the way down.

Where did I go wrong?

Error : function call ''__ct()'' does not match
''Event::Event(Object *, int)''
''Event::Event(const Event &)''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''pop_front''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : expression syntax error
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : expression syntax error
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''pop_front''
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : function call ''__ct()'' does not match
''Event::Event(Object *, int)''
''Event::Event(const Event &)''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : identifier ''insert'' redeclared
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''pop_front''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : expression syntax error
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''erase''
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : expression syntax error
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : call of non-function
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>

Error : undefined identifier ''pop_front''
(instantiating: ''deque<Event, allocator<Event>>'')
MSLHeaders++.h line 19 #include <MSLHeaders.PPC.mch>
--
"Then they placed the ark of the Lord on the cart; along with the box
containing the golden mice and the images of the hemorrhoids."
-- 1 Samuel 6:11

推荐答案

* Gregory L. Hansen:
* Gregory L. Hansen:

课程活动
{
私人:
对象*收件人;
int eventID;
public:
Event(Object * r,int e)
{recipient = r; eventID = e;}
~Event(){cout<< 事件已删除。\ n;;}
对象* get_recipient(){返回收件人;}
int get_id(){return eventID;}
};

class EventManager
{
私人:
队列<事件> event_queue;


应该是std :: queue。


// void start();
// void pop(); <公开:
// void push(事件e);
// int num_in_queue(){return 0;} // event_queue.size();}
};

当我尝试使用CodeWarrior进行编译时,我收到40条错误消息,这些消息不会标记我的任何代码。我已将它们复制到下面了,它的错误信息都是下来的。

我哪里出错?

class Event
{
private:
Object* recipient;
int eventID;
public:
Event(Object* r, int e)
{recipient = r; eventID = e;}
~Event() {cout << "Event deleted.\n";}
Object* get_recipient() {return recipient;}
int get_id() {return eventID;}
};

class EventManager
{
private:
queue<Event> event_queue;
Should be std::queue.

// void start();
// void pop();
public:
// void push(Event e);
// int num_in_queue() {return 0;}// event_queue.size();}
};

When I try to compile with CodeWarrior I get 40 error messages that don''t
flag any of my code. I''ve copied them below, and it''s error messages all
the way down.

Where did I go wrong?




将上面的代码放在一个文件中,使用类Object的虚拟定义,

并记住#include< queue> ;.


提供一个虚拟的''main''。


编译并找到任何其他错误。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



Put the code above in a file, with a dummy definition of class Object,
and remember to #include <queue>.

Provide a dummy ''main''.

Compile and find any other errors.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


* Gregory L. Hansen:
* Gregory L. Hansen:

课程活动
{
私人:
对象*收件人;


考虑在这里使用接口(纯抽象类)而不是

通用基类。 UBC通常是邪恶的。


另外,你可能需要一些智能指针而不是原始指针。


否则你可能会提到一个不存在的对象。


int eventID;


尝试对数据成员名称采用一些通用约定。


如果这不是别人代码的适配器,考虑用派生类替换

id';否则你最终会得到巨大的,多余的,无法维护的切换 - 无处不在。


呃,无论如何都要考虑! ;-)


public:
Event(Object * r,int e)
{recipient = r; eventID = e;}



~Event(){cout<< 事件已删除。\ n;;}
对象* get_recipient(){返回收件人;}


应该是''const''。

int get_id(){return eventID;}


同上。


一般来说''收件人''而不是''get_recipient' '使得更多

可读客户端代码。


};

类EventManager

class Event
{
private:
Object* recipient;
Consider using an interface (pure abstract class) here instead of
an Universal Base Class. UBCs are generally Evil.

Also, you may need some smart-pointer instead of a raw pointer.

Otherwise you risk referring to a non-existing Object.

int eventID;
Try to adopt some common convention for data member names.

If this isn''t an adaptor to someone else''s code, consider replacing
id''s with derived classes; otherwise you''ll end up with huge, redundant,
non-maintainable ''switch''-es everywhere.

Uh, consider that anyway! ;-)

public:
Event(Object* r, int e)
{recipient = r; eventID = e;}

~Event() {cout << "Event deleted.\n";}
Object* get_recipient() {return recipient;}
Should be ''const''.
int get_id() {return eventID;}
Ditto.

Generally ''recipient'' instead of ''get_recipient'' makes for more
readable client code.

};

class EventManager




''经理''是邪恶的名字。 经理可以是任何东西。如果这个

是一个队列,请考虑命名,例如''EventQueue''。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的是什么?



''Manager'' is an Evil name. A ''Manager'' could be anything. If this
is a queue, consider naming e.g. ''EventQueue''.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


文章< 42 ***************** @ news.individual.net>,

Alf P. Steinbach< al *** @ start.no>写道:
In article <42*****************@news.individual.net>,
Alf P. Steinbach <al***@start.no> wrote:
* Gregory L. Hansen:
* Gregory L. Hansen:

课程活动
{
私人:
对象*收件人;
int eventID;
public:
Event(Object * r,int e)
{recipient = r; eventID = e;}
~Event(){cout<< 事件已删除。\ n;;}
对象* get_recipient(){返回收件人;}
int get_id(){return eventID;}
};

class EventManager
{
私人:
队列<事件> event_queue;
应该是std :: queue。

class Event
{
private:
Object* recipient;
int eventID;
public:
Event(Object* r, int e)
{recipient = r; eventID = e;}
~Event() {cout << "Event deleted.\n";}
Object* get_recipient() {return recipient;}
int get_id() {return eventID;}
};

class EventManager
{
private:
queue<Event> event_queue;
Should be std::queue.




我的编译器很老了,不知道什么是std意思,并且不是

似乎使用命名空间。



My compiler is pretty old and doesn''t know what std means, and doesn''t
seem to use namespaces.

// void start();
// void pop();
public:
// void push(事件e);
// int num_in_queue(){return 0;} // event_queue.size();}
};
<当我尝试使用CodeWarrior编译时,我得到40条错误消息,它们不会标记我的任何代码。我已将它们复制到下面了,它的错误信息都是下来的。

我哪里出错?
// void start();
// void pop();
public:
// void push(Event e);
// int num_in_queue() {return 0;}// event_queue.size();}
};

When I try to compile with CodeWarrior I get 40 error messages that don''t
flag any of my code. I''ve copied them below, and it''s error messages all
the way down.

Where did I go wrong?



将上面的代码放在一个文件中,带有Object类的虚拟定义,并记住#include< queue> ;.

提供一个虚拟的''main''。

编译并找到任何其他错误。



Put the code above in a file, with a dummy definition of class Object,
and remember to #include <queue>.

Provide a dummy ''main''.

Compile and find any other errors.




哦,它有一个类Object的真正定义和一个非虚拟''main''。 br />
其他所有其他编译和运行都没有错误。我直接从发电机发送事件

到目的地 - 这是一个非常简单的和非b $ b非网络程序。然后我想我会尝试一个事件队列。我用一个字符串队列玩了

以确保我知道它们是如何工作的,当我给EventManager一个字符串队列时,上面的

编译完全正常br />
而不是活动。

-

"普通人,在一天内,存放在他或她的内衣中

一定数量的粪便细菌,相当于花生四分之一的重量。

- Robert Buckman博士,人类野生动物,第119页。



Oh, it has a real definition of class Object and a non-dummy ''main''.
Everything else compiles and runs without error. I was sending events
straight from the generator to the destination-- it''s a pretty simple and
non-networky program. Then I thought I''d try an event queue. I''ve played
with a queue of strings to make sure I know how they work, and the above
compiles perfectly fine when I give EventManager a queue of strings
rather than Events.
--
"The average person, during a single day, deposits in his or her underwear
an amount of fecal bacteria equal to the weight of a quarter of a peanut."
-- Dr. Robert Buckman, Human Wildlife, p119.


这篇关于我的队列有问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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