读书人

编译为什么通不过?该如何处理

发布时间: 2012-03-25 20:55:17 作者: rapoo

编译为什么通不过??
/////date.h文件内容///
#ifndef m
#define m
class DATE
{public:
DATE(int,int,int);
friend void display(const DATE& ,const TIME&);
private:
int month;
int day;
int year;

};
#endif
/////////////time.h的内容
#ifndef k
#define k

#include<iostream>
using namespace std;
class DATE;
class TIME
{public:
TIME(int,int,int);
friend void display(const DATE&,const TIME&);
private:
int hour;
int min;
int sec;


};
#endif
///////////hs.cpp的内容
#include"time.h"
#include"date.h"

TIME::TIME(int h,int m,int s)
{hour=h;
min=m;
sec=s;
}
DATE::DATE(int m,int d,int y)
{month=m;
day=d;
year=y;
}
void display(const DATE &d,const TIME &t)
{cout<<d.month<<"/"<<d.day<<d.year<<endl;
cout<<t.hour<<":"<<t.min<<":"<<t.sec<<endl;

}
/////////////////
当我编译hs.cpp时
Compiling...
hs.cpp
D:\程序\vc6.0组\我的工作空间\第六题\第八题\hs.cpp(6) : error C2059: syntax error : ';'
D:\程序\vc6.0组\我的工作空间\第六题\第八题\hs.cpp(10) : error C2059: syntax error : ';'
Error executing cl.exe.

第八题.exe - 2 error(s), 0 warning(s)
/////////////////
错在哪里啊?


[解决办法]
额...貌似和你定义的
#ifndef m
#define m

冲突了吧

[解决办法]

C/C++ code
// 定义保护宏时能不能多写2字#ifndef _m_H #define _m_H class DATE {public: DATE(int,int,int); friend void display(const DATE& ,const TIME&); private: int month; int day; int year; }; #include"time.h" #include"date.h" TIME::TIME(int h,int m,int s) {hour=h; min=m;       // 不然这儿的m会被替换! 替换为空的,因为 #define msec=s; } DATE::DATE(int m,int d,int y) {month=m;    // 这儿也是 day=d; year=y; } void display(const DATE &d,const TIME &t) {cout < <d.month < <"/" < <d.day < <d.year < <endl; cout < <t.hour < <":" < <t.min < <":" < <t.sec < <endl; } 

读书人网 >C++

热点推荐