-2
私は2つのクラスとメインを持っています。 People.hC++一般的なエラークラスコンストラクタ
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;
}
を私は見つけることができる最善のようにすべてのものを踏襲しているが、どれがエラーを識別するのに役立ち、まだ持っているエラー
はよく
を受けたことになります
#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;
}
質問にエラーメッセージを含めてください(プレーンテキスト、画像なし) – user463035818
これがVisual Studioの場合は、出力タブからエラーメッセージのテキストをコピーしてください。 'Alt-2' – drescherjm
はコピー貼りの間違いですか、Birthday.cppに' class Birthday'の2番目の宣言がありますか? – user463035818