C++重载成员函数错误

标签 c++ visual-studio visual-studio-2010 overloading

你好,我正在制作一个包含 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/

相关文章:

node.js - Windows 错误删除 node_modules 文件夹 : Source Path Too Long

c++ - 将 std::strings 的 std::vector 解析为任意类型的 std::tuple

c++ - 如何使用 jsoncpp 将列表中的特定值保存到 txt?

css - 为什么 .scss 文件中的更改会转换为 .css 文件

c# - Finisar.SQLite.SQLiteException : SQL logic error or missing database: unrecognized token: "$"

c++ - VS2010 C++ 可变参数模板示例

add-in - Fogbugz 的 VS 2010 插件?

c# - 如何在托管函数中 Hook 非托管函数?

c++ - 捕获安静的 NaN

c# - HTTP 错误 500.52 - URL 重写模块错误。名称属性