开发者

C++ overloaded member function error

hi i was making a program with 3 classes and when i was using a member initialization list i got an error saying "no instance of overloaded function "people::people" matches the specified type:

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


People.cpp should be:

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


You havn't implemented the people(string x, birthday bo); constructor. in your PEOPLE.cpp, change

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

to

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


Your constructor in PEOPLE.cpp has the wrong signature:

It should be:

people::people(string x, birthday bo)

Instead of:

people::people()


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

You have forgotten your arguments to this constructor.


poeple ctor declaration and definition doesn't match!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜