include vector 报错,请帮忙

sprawd 2008-05-29 09:46:17
我定义了个控制台项目,在main.cpp中#include<vector>没问题
然后,自己写了一个类t1.h然后在main中include“t1.h”.
如果在t1.h中再#include<vector>就开始报错,我把main.cpp中的#include<vector>删掉也不行。
main 和 t1里面就个大括号,没写代码呢。

帮忙谢谢阿



报错类似于
1>main.cpp
1>d:\program files\microsoft visual studio 8\vc\include\xutility(1023) : error C2059: syntax error : ','
1> d:\program files\microsoft visual studio 8\vc\include\xutility(1026) : see reference to class template instantiation 'std::_Ptr_cat_helper<<unnamed-symbol>,_T2>' being compiled
1>d:\program files\microsoft visual studio 8\vc\include\xutility(1024) : error C2976: 'std::_Checked_iterator_category' : too few template arguments
1> d:\program files\microsoft visual studio 8\vc\include\xutility(874) : see declaration of 'std::_Checked_iterator_category'
1>d:\program files\microsoft visual studio 8\vc\include\xutility(1025) : error C2976: 'std::_Ptr_cat_with_checked_cat_helper' : too few template arguments
1> d:\program files\microsoft visual studio 8\vc\include\xutility(1018) : see declaration of 'std::_Ptr_cat_with_checked_cat_helper'
..............
..............
t1.cpp
1>d:\program files\microsoft visual studio 8\vc\include\xutility(1023) : error C2059: syntax error : ','
..........
.........

...全文
662 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sprawd 2008-05-29
  • 打赏
  • 举报
回复
谢谢大家,解决了,虽然不知道为什么

ps: 分号是小问题,即使没有这个错误,一样通不过

需要把#include<vector>提到#ifndef之前才能行。

我不知道为什么,那位高手能给说明一下吗?
Alix-Lei 2008-05-29
  • 打赏
  • 举报
回复
vector<int>aa后面没分号!
偶像罗斯福 2008-05-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 babyvox1999 的回复:]
引用 6 楼 taodm 的回复:
vector <int > aa
};

你不觉得少了点什么么?
[/Quote]
低级错误啊,少个 ;
babyvox1999 2008-05-29
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 taodm 的回复:]
vector <int > aa
};

你不觉得少了点什么么?
[/Quote]
taodm 2008-05-29
  • 打赏
  • 举报
回复
vector <int > aa
};

你不觉得少了点什么么?
sprawd 2008-05-29
  • 打赏
  • 举报
回复
//main.cpp//
////////////
#include "t1.h"
int main() {

}
_____________________
//t1.cpp//
//////////
#ifndef _T1
#define _T1
#include <vector>
using namespace std;
#include "t2.h"

class t1
{
public:
t1();
virtual ~t1();
void tt1(){};

vector<int > aa
};
#endif
____________
//t2.h//
////////
#ifndef _T2
#define _T2
//#include <vector>
//using namespace std;

class t2
{
public:
t2();
virtual ~t2();
void tt();
private:
//vector<int> pri;
};
#endif

___________________________
不论t1.h还是t2.h只要加<vector>就出现上述的错误
main里加没事
这个小问题折腾我两天了,请帮忙,谢谢
yatobiaf 2008-05-29
  • 打赏
  • 举报
回复
把#include <vector>放到t1.cpp里面呢?
还是没用using namespace std;
应该把代码贴上来看看
hastings 2008-05-29
  • 打赏
  • 举报
回复
什么叫main 和 t1里面就个大括号,没写代码呢?
ahuisafe 2008-05-29
  • 打赏
  • 举报
回复
把代码贴出来看看 不一定是#include<vector>的问题
  • 打赏
  • 举报
回复
t1.h里面的内容是什么?
zxwl 2008-05-29
  • 打赏
  • 举报
回复
main.cpp 里面保护了 t1.h

可你怎么把
#include <vector>
放到t1.cpp里去了呢
sprawd 2008-05-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 ZF78 的回复:]
1、“文件”并不是C++语言定义的一部分;
2、#ifndef...是头文件里的包含保护符,是头文件的内容;
3、#include...包含的是头文件,而不是当前头文件的内容(我承认,这个说法不够严谨);
因此,……
[/Quote]

不好意思,没看懂- -||
"文件"指什么呢?
为什么我写DLL的时候,就没出现这样的问题呢?
还是谢谢你的解答
十年拱卒 2008-05-29
  • 打赏
  • 举报
回复
1、“文件”并不是C++语言定义的一部分;
2、#ifndef...是头文件里的包含保护符,是头文件的内容;
3、#include...包含的是头文件,而不是当前头文件的内容(我承认,这个说法不够严谨);
因此,……

65,202

社区成员

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

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