gpt4 book ai didi

C++重载成员函数错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:17:08 26 4
gpt4 key购买 nike

你好,我正在制作一个包含 3 个类的程序,当我使用成员初始化列表时,我收到一条错误消息:“没有重载函数实例“people::people”与指定类型匹配:

主要.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();
}

生日.h

    #pragma once
class birthday
{
public:
birthday(int d, int m, int y);
void printdate();
private:
int month;
int day;
int year;
};

生日.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;
}

人物.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();
}

最佳答案

People.cpp 应该是:

people::people(string x, birthday bo) : name(x), dateOfBirth(bo) { } 

关于C++重载成员函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7175982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com