VC++的问题!!急!!!

来源:百度知道 编辑:UC知道 时间:2024/05/25 07:21:16
member function definition looks like a ctor, but name does not match enclosing class 是什么编译错误?
帮我找一下这个有什么错误啊!只有一个错误!请高手一定指点指点
#include <iostream>
using namespace std;
class Date
{
private:
int year;
int month;
int day;
public:
Date()
{
year=2007;
month=05;
day=01;
}
Date(int y,int m,int d):year(y),month(m),day(d){}
~Date()
{
cout<<"执行析构函数"<<endl;
}
void showDate()
{
cout<<year<<":"<<month<<":"<<day<<endl;
}
};
Date Datetime1();
void main()
{
Date Datetime2(2007,05,17);
static Date Datetime3(2007,05,17);
Datetime1.showDate();/*错误在这一行 left of '.showDate' must have class/struct/union type*/

Datetime2.showDate();
Datetime3.showDate();
}

直译:一个成员函数的定义看起来像构造函数,但是函数名与类并不匹配;

看看是不是函数没写返回类型?

编译错误,把错误码也一起贴出来的话,别人也比较容易找一些:)

Date Datetime1();这句编译器认定是一个函数,而不是定义一个函数;
Date Datetime1;没有参数的话这么写;

把Date Datetime1(); 这句放到去掉()
构造函数用错了