找不到c++成员声明

C++ Member Declaration not found

本文关键字:声明 成员 c++ 找不到      更新时间:2023-10-16

我是一个业余的c++程序员,我开始使用类和对象。我想创建一个小的"程序",它可以输入一个人的生日和名字并显示出来。我设计了一个程序,你只需要输入你的生日日期、年份、月份和名字就可以了。它会显示出来。我总是在People.h和People.cpp中出现错误:"Member declaration not found"错误候选人是:std::People::People(const std::People&)People.h 和'std::People::People()'的原型不匹配'std::People'类中的任何一个People.cpp

如果你需要的话,我在底部的两个图像中包含了Birthday.h和Birthday.cpp。抱歉我的格式混乱,这是我的第二篇文章,我试图让事情可读,但我有点失败。: P

My Main.cpp is:
#include "Birthday.h"
#include "People.h"
#include <iostream>
using namespace std;
int main() {
    Birthday birthObj(4,16,2002);
    People ethanShapiro("Ethan Shapiro", birthObj);
    return 0;
}
People.h is:
    #ifndef PEOPLE_H_
#define PEOPLE_H_
#include <iostream>
#include "Birthday.h"
#include <string>
namespace std {
class People {
    public:
        People(string x, Birthday bo);
        void printInfo();
    private:
        string name;
        Birthday dateOfBirth;
};
}
#endif
People.cpp is:
    #include "People.h"
namespace std {
People::People(): name(x), dateOfBirth(bo) {
}
void People::printInfo(){
    cout << name << " is born in";
    dateOfBirth.printDate();
}
}

Birthday.hBirthday.cpp

People的唯一构造函数声明为:

    People(string x, Birthday bo);

,你定义的构造函数是:

People::People(): name(x), dateOfBirth(bo) {
}

定义不匹配任何声明。

你需要使用:

People::People(string x, Birthday bo): name(x), dateOfBirth(bo) {
}