[英]Overloaded member function not found
I have a problem with my code, the error is: 我的代码有问题,错误是:
1>c:\users\grother\documents\obiektowe\lab05_195975\lab05_195975\czlowiek.cpp(6): error C2511: 'czlowiek::czlowiek(void)' : overloaded member function not found in 'czlowiek'
1>c:\users\grother\documents\obiektowe\lab05_195975\lab05_195975\czlowiek.h(3) : see declaration of 'czlowiek'
This is czlowiek.h
这是
czlowiek.h
class czlowiek
{
private:
public:
int wiek, pola, r;
char plec, *p, imie[15], nazwisko[25];
static int n;
string ulubioneKsiazki;
//czlowiek();
virtual ~czlowiek();
czlowiek(const string& ulubioneKsiazki="Brak informacji")
{
this->ulubioneKsiazki=ulubioneKsiazki;
};
};
and this is czlowiek.cpp
: 这是
czlowiek.cpp
:
#include "stdafx.h"
#include "czlowiek.h"
int czlowiek::n=0;
czlowiek::czlowiek():p(0)
{
n++;
}
czlowiek::~czlowiek()
{
n--;
}
I've tried changing the constructor, but I have no idea how to make this one work. 我尝试过更改构造函数,但我不知道如何使这一工作正常。 Thanks in advance :)
提前致谢 :)
You need to remove the definition of the default constructor from your .cpp
file, since you have a single parameter constructor with a default parameter: 您需要从
.cpp
文件中删除默认构造函数的定义,因为您只有一个带有默认参数的参数构造函数:
czlowiek(const string& ulubioneKsiazki="Brak informacji")
{
this->ulubioneKsiazki=ulubioneKsiazki;
};
This acts as a default constructor, since it can be invoked without arguments. 这可以用作默认构造函数,因为可以在不带参数的情况下调用它。
Another alternative is to remove the default parameter in the single parameter constructor, and add a declaration for the default constructor. 另一种选择是删除单参数构造函数中的默认参数,并为默认构造函数添加一个声明。 For example:
例如:
czlowiek() : ulubioneKsiazki="Brak informacji" {}
czlowiek(const string& ulubioneKsiazki) : ulubioneKsiazki(ulubioneKsiazki) {}
Bear in mind that your class has quite a few other data members that should probably be initialized. 请记住,您的类还有很多其他数据成员可能应该初始化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.