2011-08-24 121 views
1

嗨,我正在做一個程序與3類,當我使用成員初始化列表時,我得到一個錯誤,說「沒有重載函數實例people :: people」匹配指定的類型:C++重載的成員函數錯誤

Main.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(); 
    } 

BIRTHDAY.h

#pragma once 
    class birthday 
    { 
    public: 
birthday(int d, int m, int y); 
     void printdate(); 
    private: 
     int month; 
     int day; 
     int year; 
    }; 

BIRTHDAY.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; 
    } 

PEOPLE.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; 
    }; 

PEOPLE.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(); 
    } 
+0

哪條線產生的錯誤? –

回答

1

People.cpp應該是:

people::people(string x, birthday bo) : name(x), dateOfBirth(bo) { } 
+0

感謝所有的幫助 – Olafgarten

-1

永世構造函數的聲明和定義不匹配!

+0

感謝大家的幫助 – Olafgarten

+0

爲什麼選擇倒票? – Simon

0

你在PEOPLE.cpp構造的簽名錯誤:

應該

人::人(串x,生日BO)

代替

人::人()

+0

感謝所有的幫助 – Olafgarten

0
people::people() 
: name(x), dateOfBirth(bo) 
{ 
} 

您忘記了您對此構造函數的參數。

+0

感謝所有的幫助 – Olafgarten

0

您沒有實現people(string x, birthday bo);構造函數。在PEOPLE.cpp,改變

people::people() 
    : name(x), dateOfBirth(bo) 

people::people(string x, birthday bo) 
    : name(x), dateOfBirth(bo) 
+0

感謝大家的幫助 – Olafgarten