Thread: Constructors: No Matching function for call error

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    3

    Constructors: No Matching function for call error

    Hi,

    This is probably gonna be something really simple! but please help..

    The problem seems to be with the Registration constructor. I get a candidates are Person::Person(QString,QString,QString)

    I thought that was what I was doing! Umm, there are no default constructors

    I have the following headers:

    Code:
    class Person
    {
    public:
    
    Person(QString,QString,QString);
    QString getName();
    QString getEmail();
    QString getAffiliation();
    QString toString();
    private:
    QString m_Name;
    QString m_Email;
    QString m_Affiliation;
    
    };
    class Registration: public Person
    {
    public:
    Registration(QString,QString,QString);
    Person getAttendee();
    QDate getBookingDate();
    double calculateFee();
    QString toString()const;
    private:
    Person m_Attendee;
    QDate m_BookingDate;
    static const double STANDARD_FEE;
    };
    
    and the constructors look like this

    Code:
    Person::Person(QString n,QString e,QString a)
    {
    m_Name=n;
    m_Email=e;
    m_Affiliation=a;
    }Registration::Registration(QString n,QString e,QString a) : m_Attendee(n,e,a)
    {
    m_BookingDate=QDate::currentDate();
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Based on your code, I suggest:
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Also when you get compiler errors post the complete error messages, exactly as they appear in your development environment. These messages have important information to aid in location and repair of the problem.

    Jim

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Your Registration class is both derived from and contains a Person object? I would think you'd want one or the other but not both. Change Registration class so it is not derived from a Person object and you should be OK.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    3
    Hi,

    - Sorry indentations disappeared with copy and paste..
    - I agree on the param names, the question was using them
    - I have been reading up on initializer lists, but guess I'm missing something?
    - point taken on parameter names

    Here is updated code
    Code:
    classPerson
    {
    public:
    
    Person(QStringname,QStringemail,QStringaffiliation);
    QStringgetName();
    QStringgetEmail();
    QStringgetAffiliation();
    QStringtoString();
    private:
    QStringm_Name;
    QStringm_Email;
    QStringm_Affiliation;
    
    };
    classRegistration:publicPerson
    {
    public:
    Registration(QStringname,QStringemail,QStringaffiliation);
    PersongetAttendee();
    QDategetBookingDate();
    doublecalculateFee();
    QStringtoString()const;
    private:
    Personm_Attendee;
    QDatem_BookingDate;
    staticconstdoubleSTANDARD_FEE;
    };
    Person::Person(QStringname,QStringemail,QStringaffiliation)
    {
    m_Name=name;
    m_Email=email;
    m_Affiliation=affiliation;
    }
    
    Registration::Registration(QStringname,QStringemail,QStringaffiliation):m_Attendee(name,email,affiliation)
    {
    m_BookingDate=QDate::currentDate();
    }

  6. #6
    Registered User
    Join Date
    Mar 2012
    Posts
    3
    Quote Originally Posted by hk_mp5kpdw View Post
    Your Registration class is both derived from and contains a Person object? I would think you'd want one or the other but not both. Change Registration class so it is not derived from a Person object and you should be OK.
    Hit the nail on the head!! Many thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No matching function? [C++ Error]
    By GianluTB in forum C++ Programming
    Replies: 5
    Last Post: 01-16-2012, 10:33 AM
  2. Replies: 8
    Last Post: 07-08-2011, 01:16 PM
  3. No Matching Function Call for Constructor
    By manasij7479 in forum C++ Programming
    Replies: 5
    Last Post: 02-07-2011, 03:29 PM
  4. Replies: 2
    Last Post: 02-27-2009, 12:46 PM
  5. no matching function for call to
    By f6ff in forum C++ Programming
    Replies: 4
    Last Post: 06-10-2006, 03:34 PM