实现堆栈(错误:代码未命名类型) [英] Implementing Stack (Error: code does not name a type)

查看:77
本文介绍了实现堆栈(错误:代码未命名类型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在阅读一些有关使用我们自己的类实现Stack的文章.对此的定义位于Stack.h文件中,而代码则位于Stack.cpp文件中.这是我的Stack.h文件

Hi,
I was reading some text about the implementation of Stack using using our own class. The definition for this is placed in Stack.h file and code in Stack.cpp file. Here''s my Stack.h file

typedef char Stack_entry;
const int maxstack=10;
class Stack
{
public:
Stack();
Error_code push(const Stack_entry &item);
Error_code pop();
Error_code top(Stack_entry &item)const;
bool empty()const;
private:
int count;
Stack_entry entry[maxstack];
};



在Stack.cpp的一种方法中,我写了



In one of my methods in Stack.cpp, I write

Error_code Stack::push(const Stack_entry &item)
/*Post:Count is increased by one if the outcome is success*/
{
Error_code outcome=sucess;
if(count>=maxstack)
{
outcome=overflow;
}
else
{
entry[count++]= item;
}
return outcome;
}


如果作者在一般情况下使用了此Error_code,我会感到困惑吗?
如果没有,我们如何提及Error_code的类型?
Error_code具有一个名为result的变量,该变量最初设置为成功.实际返回时,返回的是什么?
例如:当我们返回时,我们知道我们正在返回一个数字,char返回一个字母,但是这种类型的Error_code是什么?

我已经在Stack.h中将三个方法声明为Error_code


I am confused if this Error_code was being used in general context by the author?
If not, how do we mention the type for Error_code?
Error_code has a variable named outcome which is initially set to success. When this is returned actually, what''s being returned?
For eg: When we return, we know we are returning a number, char returns an alphabet but what is this type Error_code?

I have declared three methods as Error_code in Stack.h as

Error_code push(const Stack_entry &item);
Error_code pop();
Error_code top(Stack_entry &item)const;


在编译自己的Stack类时,出现错误Error_code未命名类型. :-|


While compiling my own Stack class, I am getting the error that Error_code does not name a type. :-|

推荐答案

Error_code可能是枚举,如下所示:
The Error_code is probably an enum, like the following:
enum Error_code
{
  success,
  // other error code items here
  overflow
};



我想您应该再次检查该书,以查找其实际定义.
:)



I suppose you should check again the book, looking for its actual definition.
:)


右键单击它,看看编译器上是否显示转到定义".如果不是,请搜索枚举Error_code,#define Error_code,struct Error_code或Error_code类以对其进行跟踪.

希望它不是一个枚举,因为如果可能的话,它很可能设计不当.
Right click on it and see if you see "go to definition" on your compiler. If not, search for enum Error_code, #define Error_code, struct Error_code, or class Error_code to track it down.

Hopefully it is NOT an enum since it will most likely be poorly designed if it is.


这篇关于实现堆栈(错误:代码未命名类型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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