Results 1 to 2 of 2

Thread: please help with: no matching function error

  1. #1
    Join Date
    Apr 2014
    Location
    South Africa
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question please help with: no matching function error

    Please help with the following errors:

    In constructor 'Savings::Savings(QString, QDate, double, double)':
    error: no matching function for call to 'Assets::Assets(QString&, QDate&)'
    note: candidates are: Assets::Assets(QString, QDate, QString, double)
    note: Assets::Assets()
    note: Assets::Assets(const Assets&)

    here is my Asset code: (there are other classes that are not included here)

    Asset.h

    Qt Code:
    1. #ifndef ASSETS_H
    2. #define ASSETS_H
    3.  
    4. #include <QString>
    5. #include <QDate>
    6.  
    7. class Assets : public QObject {
    8.  
    9. Q_OBJECT
    10. Q_PROPERTY(QString description READ getDescription WRITE setDescription NOTIFY descriptionChanged);
    11. Q_PROPERTY(QDate date READ getDate WRITE setDate NOTIFY dateChanged );
    12. Q_PROPERTY(QString type READ getType WRITE setType NOTIFY typeChanged);
    13. Q_PROPERTY(double price READ getPrice WRITE setPrice NOTIFY valueChanged );
    14. public:
    15. Assets();
    16. Assets(QString des, QDate dat, QString t, double p);
    17.  
    18. void setDescription(QString des);
    19. QString getDescription() const;
    20.  
    21. void setDate(QDate dat);
    22. QDate getDate() const;
    23.  
    24. void setType(QString t);
    25. QString getType() const;
    26.  
    27. void setPrice(double p);
    28. double getPrice() const;
    29.  
    30. QString toString() const;
    31. virtual double value() const = 0;
    32. private:
    33. QString description;
    34. protected:
    35. QDate date;
    36. QString type;
    37. double price;
    38. };
    39.  
    40. #endif // ASSETS_H
    To copy to clipboard, switch view to plain text mode 

    Assets.cpp code

    Qt Code:
    1. #include "assets.h"
    2.  
    3. Assets::Assets()
    4. {
    5. description = QString();
    6. date = QDate::currentDate();
    7. type = QString();
    8. price = 0.0;
    9. }
    10.  
    11. Assets::Assets(QString des, QDate dat, QString t, double p):
    12. description(des), date(dat), type(t), price(p)
    13. {}
    14.  
    15.  
    16. void Assets::setDescription(QString des)
    17. {
    18. description = des;
    19. }
    20.  
    21. QString Assets::getDescription() const
    22. {
    23. return description;
    24. }
    25.  
    26. void Assets::setType(QString t)
    27. {
    28. type = t;
    29. }
    30.  
    31. QString Assets::getType() const
    32. {
    33. return type;
    34. }
    35.  
    36. void Assets::setDate(QDate dat)
    37. {
    38. date = dat;
    39. }
    40.  
    41. QDate Assets::getDate() const
    42. {
    43. return date;
    44. }
    45.  
    46. void Assets::setPrice(double p)
    47. {
    48. price = p;
    49. }
    50.  
    51. double Assets::getPrice() const
    52. {
    53. return price;
    54. }
    55.  
    56. QString Assets::toString() const
    57. {
    58. return QString("Description " + description + " Date " + date.toString("dd MMMM yyyy"));
    59. }
    To copy to clipboard, switch view to plain text mode 


    here is Saving.h code

    Qt Code:
    1. #ifndef SAVINGS_H
    2. #define SAVINGS_H
    3.  
    4. #include "assets.h"
    5.  
    6. class Savings : public Assets
    7. {
    8. private:
    9. double currentValue;
    10. double interestRate;
    11. public:
    12. Savings(QString des, QDate dat, double cv, double ir);
    13. void changeValue(double amount);
    14. void addInterest();
    15. double value() const;
    16. QString toString() const;
    17. };
    18.  
    19. #endif // SAVINGS_H
    To copy to clipboard, switch view to plain text mode 

    Savings.cpp code

    Qt Code:
    1. #include "savings.h"
    2.  
    3. Savings::Savings(QString des, QDate dat, double cv, double ir)
    4. : Assets(des, dat), currentValue(cv), interestRate(ir)
    5. {}
    6.  
    7. void Savings::changeValue(double amount) {
    8. currentValue += amount;
    9. }
    10.  
    11. double Savings::value() const {
    12. return currentValue;
    13. }
    14.  
    15. void Savings::addInterest() {
    16. currentValue += currentValue*interestRate/1200.0;
    17. }
    18.  
    19. QString Savings::toString() const{
    20. return QString("[Savings Assets] %1 \nAn amount of %2 represent Savings assets.")
    21. .arg(Assets::toString())
    22. .arg(currentValue)
    23. .arg(interestRate);
    24. }
    To copy to clipboard, switch view to plain text mode 

    and part of Savings.cpp code where the compiler complains

    Savings::Savings(QString des, QDate dat, double cv, double ir)
    : Assets(des, dat), currentValue(cv), interestRate(ir)
    {}
    Last edited by anda_skoa; 1st April 2015 at 07:51. Reason: fixing code tags

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: please help with: no matching function error

    You have no constructor for Assets that takes two QStrings.

    You have to either add a constructor that takes only two QString arguments, add the two missing arguments to use the existing constructor, or give them default values in the header declaration such as:

    Qt Code:
    1. Assets(QString des, QDate dat, QString t = "", double p = 0);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jefftee for this useful post:

    NtobekoQt (1st April 2015)

Similar Threads

  1. Replies: 5
    Last Post: 5th December 2013, 04:37
  2. Replies: 2
    Last Post: 10th June 2012, 12:48
  3. error: no matching function for call to ‘QTimer:
    By saman_artorious in forum Qt Programming
    Replies: 2
    Last Post: 21st May 2012, 15:27
  4. Replies: 1
    Last Post: 1st December 2010, 11:02
  5. no matching function error
    By arpspatel in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2009, 15:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.