c++编译问题

zzyjsjcom 2006-12-08 04:50:05
以下代码分别在三个文件中,其中文件 ex6_2.cpp和文件ex6_2test.cpp都包含头文件iosteream 为什么在vc 6.0没出现错误呢?
// ex6_2.h
// constructors & destructors
#ifndef EX6_2_H
#define EX6_2_H
class simple
{
public:
simple();
~simple();
};
#endif //EX6_2_H



// ex6_2.cpp
#include "ex6_2.h"
#include <iostream>
using namespace std;
simple::simple()
{
cout<<"constructors is running!"<<endl;
}

simple::~simple()
{
cout<<"destructors is running!"<<endl;
}


// ex6_2test.cpp
#include "ex6_2.h"
#include <iostream>
using namespace std;
int main()
{
simple s;
}
...全文
145 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzyjsjcom 2006-12-12
  • 打赏
  • 举报
回复
谢谢 各位大哥
abblly 2006-12-08
  • 打赏
  • 举报
回复
为什么在vc 6.0没出现错误呢?
---------------
那相当于问你自己为什么要在同文件中用
#ifndef EX6_2_H
#define EX6_2_H
#endif //EX6_2_H

iostream也用了类似的东西
aflyinghorse 2006-12-08
  • 打赏
  • 举报
回复
为什么会出错呢? 连接时连接器会去调重复的定义, 只保留一份实现
horeaper 2006-12-08
  • 打赏
  • 举报
回复
楼主想问什么?是想问“为什么没有出错”还是问“我编译的时候就出现了一大堆错误”?
Estfania 2006-12-08
  • 打赏
  • 举报
回复
iostream.h也有
#ifndef
#define
...
...
...
#endif

64,651

社区成员

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

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