请教:
#define string80 char[80]
class CDate
{
public:
CDate()
{ }
CDate(int y,int m,int d)
{SetDate(y,m,d);}
void SetDate(int y,int m,int d)
{
Year=y;
Month=m;
Day=d;
} void GetStringDate(string80 &CDate)
{
sprintf(CDate,"%d/%d/%d",Year,Month,Day);
} protected
int Year,Month,Day;
};
编译时提示为:
Deleting intermediate files and output files for project 'Mytest13 - Win32 Debug'.
--------------------Configuration: Mytest13 - Win32 Debug--------------------
Compiling...
main.cpp
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : error C2143: syntax error : missing ')' before '&'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : error C2143: syntax error : missing ';' before '&'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(17) : error C2580: redefinition of class name 'CDate'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : see declaration of 'CDate'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(17) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.Mytest13.exe - 5 error(s), 0 warning(s)
各位大哥,我是才错误在哪里啊?谢谢!
#define string80 char[80]
class CDate
{
public:
CDate()
{ }
CDate(int y,int m,int d)
{SetDate(y,m,d);}
void SetDate(int y,int m,int d)
{
Year=y;
Month=m;
Day=d;
} void GetStringDate(string80 &CDate)
{
sprintf(CDate,"%d/%d/%d",Year,Month,Day);
} protected
int Year,Month,Day;
};
编译时提示为:
Deleting intermediate files and output files for project 'Mytest13 - Win32 Debug'.
--------------------Configuration: Mytest13 - Win32 Debug--------------------
Compiling...
main.cpp
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : error C2143: syntax error : missing ')' before '&'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : error C2143: syntax error : missing ';' before '&'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(17) : error C2580: redefinition of class name 'CDate'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(16) : see declaration of 'CDate'
c:\program files\microsoft visual studio\myprojects\mytest13\date.h(17) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.Mytest13.exe - 5 error(s), 0 warning(s)
各位大哥,我是才错误在哪里啊?谢谢!
#include<string>
#include<stdio.h>
using namespace std;
class CDate
{
public:
CDate()
{ }
CDate(int y,int m,int d)
{SetDate(y,m,d);}
void SetDate(int y,int m,int d)
{
Year=y;
Month=m;
Day=d;
}void GetStringDate(char CDate[80])
{
sprintf(CDate,"%d/%d/%d",Year,Month,Day);
}protected: //protected 改为protected :
int Year,Month,Day;
};
void main()
{}
using namespace std;这是用到了命名空间是吗?
为什么要用命名空间?#include<string>
#include<stdio.h>
using namespace std;和
#include<string>
#include<stdio.h>有什么区别啊?谢谢!