C ++常规错误类构造函数

时间:2016-10-08 13:09:20

标签: c++

我有两个班级和一个班级。我尽可能地遵循了一切,但仍然有错误

任何帮助确定错误都会得到好评

Error Message here

的main.cpp

#include "People.h"
#include "Birthday.h"

int main()
{
    Birthday birthObject(8, 7, 1987);

    birthObject.printDate();

    People danielGadd("DanielGadd", birthObject);

    danielGadd.printInfo();

    return 0;
}

People.h

#ifndef PEOPLE_H
#define PEOPLE_H
#include <string>
#include "Birthday.h"

class People
{
public:
    People(std::string x, Birthday b);
    void printInfo();

private:
    std::string name;
    Birthday dateOfBirth;
};

#endif // PEOPLE_H

People.cpp

#include "People.h"
#include "Birthday.h"

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

void People::printInfo() {
    std::cout << name << " was born on ";
    dateOfBirth.printDate();
}

Birthday.h

#ifndef BIRTHDAY_H
#define BIRTHDAY_H
#include <iostream>

class Birthday
{
public:
    Birthday(int d, int m, int y);
    void printDate();
private:
    int day;
    int month;
    int year;
};

#endif //BIRTHDAY_H

Birthday.cpp

#include "Birthday.h"

Birthday::Birthday(int d, int m, int y)
{
    day = d;
    month = m;
    year = y;
}


void Birthday::printDate()
{
    std::cout << day << "/" << month << "/" << year << std::endl;
}

1 个答案:

答案 0 :(得分:0)

我正在使用Virtual Studio 2015.我找到了解决方案。我简单地从调试文件夹中删除了People.exe并再次构建了项目。它奏效了。 Al;所以类似的问题我删除了文件并重新制作它。粘贴相同的代码并修复了问题。不知道为什么