没有适当的默认构造函数可用,并且不存在默认构造函数 [英] No appropriate default constructor available and no default constructor exist
本文介绍了没有适当的默认构造函数可用,并且不存在默认构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C ++的新手,试图写一个Date Class程序来对日期进行一些计算。
I am new to C++ and trying to write a "Date Class" program that make some calculations on dates.
这两个错误对我来说:
错误C2512:'Date':没有适当的默认构造函数
error C2512: 'Date' : no appropriate default constructor
IntelliSense:对于类Date存在
IntelliSense: no default constructor exists for class "Date"
在类中声明一个对象的行:
In the line that i have declare an object from the class:
int _tmain(int argc, _TCHAR* argv[])
{
Date d;
}
.h
file:
public:
Date(int, int, int);
实施:
Date::Date(int d= 0, int m= 0, int y= 0)// DEFAULT CONSTRUCTOR
{
d = m = y = 0;
}
请帮助我,为什么会出现这个错误?
Please help me, why this error appear?
推荐答案
执行此操作:
.h文件中的构造函数:
The constructor in the .h file:
public:
Date(int=0, int=0, int=0);
实施:
Date::Date(int d, int m, int y)// DEFAULT CONSTRUCTOR
{
// Initialize data of this class
}
方法的原型/声明应该提及默认参数,而不是实现。
The prototype/declaration of method should mention the default arguments, not the implementation.
这篇关于没有适当的默认构造函数可用,并且不存在默认构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文