SOS!:VC6与Dec-cpp4.9.9.2编译不同的问题~ (多文件组织的问题~ )
为什么以下包含三个文件的程序在VC6可以编译成功,而Devcpp不行?
*******主程序***********
#include "time.h "
//#include "date.h "
int main()
{
Time t1(10,13,56);
// Date d1(4,18,1985);
t1.display();
//getchar();
return 0;
}
************ time.h *************************
#if ! defined _TIME_H_
#define _TIME_H_
//class Date;
class Time
{
public:
Time(int, int, int);
//void display(Date &);
void display();
private:
int hour;
int minute;
int sec;
};
#endif
****************** time.cpp ***********************
#include "time.h "
//#include "date.h "
#include <iostream>
using namespace std;
Time::Time(int h,int m,int s):hour(h),minute(m),sec(s){}
void Time::display()
{
cout < < hour < < ": " < < minute < < ": " < < sec < < endl;
}
VC6可以成功编译,而devcpp却一大堆莫名其妙的错误(好像与 <iostream> 有关)。
相关问题:
以下程序怎么样弄成多文件组织的形式呢,就是接口和实现分开...
是不是有一些精髓思想~请指教~
****************程序如下***********************
#include <iostream>
using namespace std;
class Date;
class Time
{
public:
Time(int, int, int);
void display(Date &);
private:
int hour;
int minute;
int sec;
};
class Date
{
public:
Date(int, int, int);
friend void Time::display(Date &);
private:
int month;
int day;
int year;
};
Time::Time(int h,int m,int s):hour(h),minute(m),sec(s){}
void Time::display(Date &d)
{
cout < < d.month < < "/ " < < d.day < < "/ " < < d.year < < endl;
cout < < hour < < ": " < < minute < < ": " < < sec < < endl;
}
Date::Date(int m,int d,int y):month(m),day(d),year(y){}
int main()
{
Time t1(10,13,56);
Date d1(4,18,1985);
t1.display(d1);
getchar();
return 0;
}
**********************************************
100大分送给好心的高手,第一次发贴,请支持,谢谢!!!
[解决办法]
Because the "_TIME_H_ "已经被定义过了,请修改:
#if ! defined _TIME_H_
#define _TIME_H_
为:
#if ! defined _TIME_H_1_
#define _TIME_H_1_
Ok.
[解决办法]
记住C、C++标准的规定吧:以_开头的名字是留给编译器用的,自己的代码不要使用_开头。