2011-08-24 83 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