C重载成员函数错误

新手上路,请多包涵

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

主文件

    #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();
    }

原文由 Olafgarten 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 685
2 个回答

People.cpp 应该是:

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

原文由 Jiri Kriz 发布,翻译遵循 CC BY-SA 3.0 许可协议

你还没有实现 people(string x, birthday bo); 构造函数。在您的 PEOPLE.cpp 中,更改

people::people()
    : name(x), dateOfBirth(bo)

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

原文由 nos 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题