2016-10-08 16 views
-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; 
} 

を私は見つけることができる最善のようにすべてのものを踏襲しているが、どれがエラーを識別するのに役立ち、まだ持っているエラー

はよく

Error Message here

を受けたことになります

#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; 
} 
+2

質問にエラーメッセージを含めてください(プレーンテキスト、画像なし) – user463035818

+0

これがVisual Studioの場合は、出力タブからエラーメッセージのテキストをコピーしてください。 'Alt-2' – drescherjm

+3

はコピー貼りの間違いですか、Birthday.cppに' class Birthday'の2番目の宣言がありますか? – user463035818

答えて

0

は、私は解決策を見つけたバーチャルスタジオ2015を使用しています。私は単純にPeople.exeをデバッグフォルダから削除し、プロジェクトを再度ビルドしました。そしてそれは働いた。 Al;同様の問題はファイルを削除して再作成したためです。同じコードを貼り付けて問題を修正しました。考えられない理由