关于C++构造函数的定义问题!
#include<iostream.h>classA{public:A();A(inty,intm,intd){year=y;month=m;day=d;cout<<ye...
#include<iostream.h>
class A
{public:
A();
A(int y,int m,int d)
{year=y;month=m;day=d;
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
private:
int year;
int month;
int day;
}
main()
{A a(1990,2,19);
}
A(int y,int m,int d)这个构造函数在内部定义可以得出结果
但如果把程序改成
#include<iostream.h>
class A
{public:
A();
A(int y,int m,int d);
private:
int year;
int month;
int day;
}
A::A(int y,int m,int d)
{year=y;month=m;day=d;
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
void main()
{A a(1990,2,19);
}
A(int y,int m,int d);在类外定义 程序报错 求解释 哪出毛病啊? 展开
class A
{public:
A();
A(int y,int m,int d)
{year=y;month=m;day=d;
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
private:
int year;
int month;
int day;
}
main()
{A a(1990,2,19);
}
A(int y,int m,int d)这个构造函数在内部定义可以得出结果
但如果把程序改成
#include<iostream.h>
class A
{public:
A();
A(int y,int m,int d);
private:
int year;
int month;
int day;
}
A::A(int y,int m,int d)
{year=y;month=m;day=d;
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
void main()
{A a(1990,2,19);
}
A(int y,int m,int d);在类外定义 程序报错 求解释 哪出毛病啊? 展开
2个回答
展开全部
我改了一下,如下
#include<iostream>
using namespace std;
class A{
public:
A();
A(int y,int m,int d);
private:
int year;
int month;
int day;
};//注意,类定义后要加分号
A::A(int y,int m,int d){
year=y;month=m;day=d;
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
void main(){
A a(1990,2,19);
return ;
}
#include<iostream>
using namespace std;
class A{
public:
A();
A(int y,int m,int d);
private:
int year;
int month;
int day;
};//注意,类定义后要加分号
A::A(int y,int m,int d){
year=y;month=m;day=d;
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
void main(){
A a(1990,2,19);
return ;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询