C++重载成员函数错误
你好,我正在制作一个包含 3 个类的程序,当我使用成员初始化列表时,我收到一条错误消息“没有重载函数“people::people”的实例与指定类型匹配:
MAIN.cpp
#include <iostream>
#include "conio.h"
#include <string>
#include "birthday.h"
#include "people.h"
using namespace std;
void main(){
birthday birthObj (30, 06, 1987);
people me("The King",birthObj);
_getch();
}
BIRTHDAY.h
#pragma once
class birthday
{
public:
birthday(int d, int m, int y);
void printdate();
private:
int month;
int day;
int year;
};
BIRTHDAY.cpp
#include "birthday.h"
#include <iostream>
#include "conio.h"
#include <string>
using namespace std;
birthday::birthday(int d, int m, int y)
{
month = m;
day = d;
year = y;
}
void birthday::printdate()
{
cout << day << "/" << month << "/" << year;
}
PEOPLE .h
#pragma once
#include <iostream>
#include "conio.h"
#include <string>
#include "birthday.h"
using namespace std;
class people
{
public:
people(string x, birthday bo);
void printInfo();
private:
string name;
birthday dateOfBirth;
};
人物.cpp
#include "people.h"
#include <iostream>
#include "conio.h"
#include <string>
#include "birthday.h"
using namespace std;
people::people()
: name(x), dateOfBirth(bo)
{
}
void people::printInfo()
{
cout << name << " was born on ";
dateOfBirth.printdate();
}
hi i was making a program with 3 classes and when i was using a member initialization list i got an error saying "no instance of overloaded function "people::people" matches the specified type:
MAIN.cpp
#include <iostream>
#include "conio.h"
#include <string>
#include "birthday.h"
#include "people.h"
using namespace std;
void main(){
birthday birthObj (30, 06, 1987);
people me("The King",birthObj);
_getch();
}
BIRTHDAY.h
#pragma once
class birthday
{
public:
birthday(int d, int m, int y);
void printdate();
private:
int month;
int day;
int year;
};
BIRTHDAY.cpp
#include "birthday.h"
#include <iostream>
#include "conio.h"
#include <string>
using namespace std;
birthday::birthday(int d, int m, int y)
{
month = m;
day = d;
year = y;
}
void birthday::printdate()
{
cout << day << "/" << month << "/" << year;
}
PEOPLE.h
#pragma once
#include <iostream>
#include "conio.h"
#include <string>
#include "birthday.h"
using namespace std;
class people
{
public:
people(string x, birthday bo);
void printInfo();
private:
string name;
birthday dateOfBirth;
};
PEOPLE.cpp
#include "people.h"
#include <iostream>
#include "conio.h"
#include <string>
#include "birthday.h"
using namespace std;
people::people()
: name(x), dateOfBirth(bo)
{
}
void people::printInfo()
{
cout << name << " was born on ";
dateOfBirth.printdate();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
People.cpp 应该是:
People.cpp should be:
您尚未实现
people(string x,birthday bo);
构造函数。在您的 PEOPLE.cpp 中,更改为
You havn't implemented the
people(string x, birthday bo);
constructor. in your PEOPLE.cpp, changeto
PEOPLE.cpp
中的构造函数有错误的签名:它应该是:
而不是:
Your constructor in
PEOPLE.cpp
has the wrong signature:It should be:
Instead of:
您忘记了对该构造函数的参数。
You have forgotten your arguments to this constructor.
人物声明和定义不匹配!
poeple ctor declaration and definition doesn't match!