编译包含vector头文件时候出错!

grUngeJX 2008-10-31 04:40:43
源程序:
#include<vector>

class iStack {
public:
iStack(){_top = 0;}
iStack( int capacity )
: _stack( capacity ), _top( 0 ) { }
void pop( int &top_value );
void push( int value );
bool full();
bool empty();
void display();
int size();
private:
int _top;
std::vector<int> _stack;
};

#include <iostream>
#include "iStackExcep.h"
#include "istack.h"
using std::cout;
using std::endl;
void iStack::pop( int &top_value )
{
if ( empty() )
throw popOnEmpty();
top_value = _stack[ --_top ];
cout << "iStack::pop(): " << top_value << endl;
}
void iStack::push( int value )
{
cout << "iStack::push( " << value << " )\n";
if ( full() )
throw pushOnFull();
_stack[ _top++ ] = value;
}

bool iStack::full()
{
return _stack.size()==_stack.capacity()? true:false;
}

bool iStack::empty()
{
return _stack.empty();
}

int size()
{
return _stack.size();
}

void display()
{
cout << "(" ;
for( int ix = 0, ix < _stack.size(), ++ix )
cout << _stack[ix] << ",";
cout << "\b)" << endl;
}

g++显示
in file include from /usr/include/c++/4.2/vector:70
from istack.h 1,
from istack.cc 3:
/usr/include/c++/4.2/bits/stl_vector.h expected unqualified-id befor 'namespace'

这个是怎么回事?
...全文
244 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
grUngeJX 2008-10-31
  • 打赏
  • 举报
回复
没用这个 using directive
我用的是using declaraction
std::

不是这个问题
些一个简单的调用vector的程序没问题的
帅得不敢出门 2008-10-31
  • 打赏
  • 举报
回复
#include <vector>
using namespace std;
coverallwangp 2008-10-31
  • 打赏
  • 举报
回复
加上
using namespace std;

64,683

社区成员

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

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