包括订单 [英] include order

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

问题描述

您好,

我写了这个简单的堆栈:

--- START ---------------

#include" stackArr.h"

#include" underflow.h"

#include< iostream>


StackArr :: StackArr(int initialSize){

data = new void * [initialSize];

size = 0;

};


StackArr :: ~StackArr(){

删除[]数据;

}


void StackArr :: push(void * x){

data [size] = x;

size ++;

}


void StackArr :: pop(){

如果(size == 0)抛出新的下溢(Stack empty);

size--;

}


void * StackArr :: top()const {

if( size == 0)抛出新的下溢(Stack empty);

返回数据[size-1];

}


void * StackArr :: topAndPop(){

如果(size == 0)抛出新的下溢(Stack empty);

返回数据[size - ];

}

bool StackArr :: isEmpty()const {

返回大小== 0;

}


无效StackArr :: makeEmpty(){

delete [] data;

data = new void * [10];

size = 0; < br $>
}


int main(){

cout<<"" StackArr"<< endl;

}


---结束-----------------


当我编译这个版本时没有问题,但当我更改

包括订单(第一个iostream)


#include< iostream>

#include" stackArr.h"

#include" underflow.h"


我有编译错误:

stackArr.cpp:在成员函数`virtual void StackArr :: pop()'':

stackArr.cpp:23:在'(''token
stackArr.cpp:在成员函数`virtual void * StackArr :: top()const'':

stackArr.cpp:28:在'(''token <之前解析错误br />
stackArr.cpp:在成员函数中在`virtual void * StackArr :: topAndPop()'':


为什么???????

谢谢

Yuri

解决方案

yuri写道:

你好,
我写了这个简单的堆栈:


< snip>

当我编译这个版本时没有问题,但当我更改
包含顺序(第一个iostream)时>
#include< iostream>
#include" stackArr.h"
#include" underflow.h"

我有编译错误:
stackArr.cpp:在成员函数`virtual void StackArr :: pop()'':
stackArr.cpp:23:解析前的错误`(''token
stackArr.cpp:在成员函数中`virtual void * StackArr :: top()const'':
stackArr.cpp:28:解析前的错误`(''token
stackArr.cpp:在成员函数`virtual void * StackArr :: topAndPop()'':

为什么???????




可能是因为你已经完成了你的头文件有问题。我们

不知道是什么,因为你没有费心去包含这些

文件的代码。

http://www.parashift.com /c++-faq-lit...t.html#faq-5.8


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。


或者使用std :: stack模板类:-)

" yuri" <宇** @ nospam.it>在消息中写道

news:pa **************************** @ nospam.it ... < blockquote class =post_quotes>你好,
我写了这个简单的堆栈:

--- START ---------------
#include" stackArr.h"
#include" underflow.h"
#include< iostream>

StackArr :: StackArr(int initialSize){
data = new void * [initialSize];
size = 0;
};

StackArr :: ~StackArr(){
删除[]数据;
}

void StackArr :: push(void * x){
data [size] = x;
size ++;
}

void StackArr :: pop(){
如果(size == 0)抛出新的下溢(Stack empty);
size--;
}

void * StackArr :: top()const {
if(size == 0)抛出新的下溢(Stack empty);
返回数据[size-1];
}

void * StackArr :: topAndPop(){
如果(size == 0)抛出新的下溢(Stack empty);
返回数据[size - ];
}

bool StackArr :: isEmpty()const {返回大小== 0;
}
void StackArr :: makeEmpty(){
删除[]数据;
data = new void * [10 ];
size = 0;
}
int main(){
cout<<" StackArr"<< endl;
}

---结束-----------------

当我编译这个版本时没有问题,但当我更改
包含顺序(第一个iostream)
#include< iostream>
#include" stackArr.h"
#include" underflow .h"

我有编译错误:
stackArr.cpp:在成员函数`virtual void StackArr :: pop()'':
stackArr.cpp:23:解析`之前的错误'(''token
stackArr.cpp:在成员函数`virtual void * StackArr :: top()const'':
stackArr.cpp:28:在'('''令牌之前解析错误
stackArr.cpp:在成员函数`virtual void * StackArr :: topAndPop()'':

为什么???????
谢谢
Yuri



Marcin Vorbrod t写道:

或者改为使用std :: stack模板类: - )




请不要顶一下,请回复时修剪。阅读

的第5节发布指南的常见问题解答。

http://www.parashift.com/c++-faq-lite/

-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。


Hello,
I wrote this simple stack:
---START---------------
#include "stackArr.h"
#include "underflow.h"
#include <iostream>

StackArr::StackArr(int initialSize){
data = new void*[initialSize];
size = 0;
};

StackArr::~StackArr(){
delete []data;
}

void StackArr::push(void* x){
data[size] = x;
size++;
}

void StackArr::pop(){
if(size==0) throw new Underflow("Stack empty");
size--;
}

void* StackArr::top() const{
if(size==0) throw new Underflow("Stack empty");
return data[size-1];
}

void* StackArr::topAndPop(){
if(size==0) throw new Underflow("Stack empty");
return data[size--];
}

bool StackArr::isEmpty() const{
return size==0;
}

void StackArr::makeEmpty(){
delete []data;
data = new void*[10];
size=0;
}

int main(){
cout<<"StackArr"<<endl;
}

---END-----------------

When I compile this version there isn''t problem, but when I change the
include order (first iostream)

#include <iostream>
#include "stackArr.h"
#include "underflow.h"

I have compile errors:
stackArr.cpp: In member function `virtual void StackArr::pop()'':
stackArr.cpp:23: parse error before `('' token
stackArr.cpp: In member function `virtual void* StackArr::top() const'':
stackArr.cpp:28: parse error before `('' token
stackArr.cpp: In member function `virtual void* StackArr::topAndPop()'':

Why???????
Thanks
Yuri

解决方案

yuri wrote:

Hello,
I wrote this simple stack:
<snip>

When I compile this version there isn''t problem, but when I change the
include order (first iostream)

#include <iostream>
#include "stackArr.h"
#include "underflow.h"

I have compile errors:
stackArr.cpp: In member function `virtual void StackArr::pop()'':
stackArr.cpp:23: parse error before `('' token
stackArr.cpp: In member function `virtual void* StackArr::top() const'':
stackArr.cpp:28: parse error before `('' token
stackArr.cpp: In member function `virtual void* StackArr::topAndPop()'':

Why???????



Probably because you''ve done something wrong in your header files. We
don''t know what, since you didn''t bother to include the code from those
files.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


or use std::stack template class instead:-)
"yuri" <yu**@nospam.it> wrote in message
news:pa****************************@nospam.it...

Hello,
I wrote this simple stack:
---START---------------
#include "stackArr.h"
#include "underflow.h"
#include <iostream>

StackArr::StackArr(int initialSize){
data = new void*[initialSize];
size = 0;
};

StackArr::~StackArr(){
delete []data;
}

void StackArr::push(void* x){
data[size] = x;
size++;
}

void StackArr::pop(){
if(size==0) throw new Underflow("Stack empty");
size--;
}

void* StackArr::top() const{
if(size==0) throw new Underflow("Stack empty");
return data[size-1];
}

void* StackArr::topAndPop(){
if(size==0) throw new Underflow("Stack empty");
return data[size--];
}

bool StackArr::isEmpty() const{
return size==0;
}

void StackArr::makeEmpty(){
delete []data;
data = new void*[10];
size=0;
}

int main(){
cout<<"StackArr"<<endl;
}

---END-----------------

When I compile this version there isn''t problem, but when I change the
include order (first iostream)

#include <iostream>
#include "stackArr.h"
#include "underflow.h"

I have compile errors:
stackArr.cpp: In member function `virtual void StackArr::pop()'':
stackArr.cpp:23: parse error before `('' token
stackArr.cpp: In member function `virtual void* StackArr::top() const'':
stackArr.cpp:28: parse error before `('' token
stackArr.cpp: In member function `virtual void* StackArr::topAndPop()'':

Why???????
Thanks
Yuri



Marcin Vorbrodt wrote:

or use std::stack template class instead:-)



Please don''t top-post, and please trim when replying. Read section 5 of
the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


这篇关于包括订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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