PDA

View Full Version : please help with: no matching function error



NtobekoQt
31st March 2015, 12:48
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


#ifndef ASSETS_H
#define ASSETS_H

#include <QString>
#include <QDate>

class Assets : public QObject {

Q_OBJECT
Q_PROPERTY(QString description READ getDescription WRITE setDescription NOTIFY descriptionChanged);
Q_PROPERTY(QDate date READ getDate WRITE setDate NOTIFY dateChanged );
Q_PROPERTY(QString type READ getType WRITE setType NOTIFY typeChanged);
Q_PROPERTY(double price READ getPrice WRITE setPrice NOTIFY valueChanged );
public:
Assets();
Assets(QString des, QDate dat, QString t, double p);

void setDescription(QString des);
QString getDescription() const;

void setDate(QDate dat);
QDate getDate() const;

void setType(QString t);
QString getType() const;

void setPrice(double p);
double getPrice() const;

QString toString() const;
virtual double value() const = 0;
private:
QString description;
protected:
QDate date;
QString type;
double price;
};

#endif // ASSETS_H

Assets.cpp code


#include "assets.h"

Assets::Assets()
{
description = QString();
date = QDate::currentDate();
type = QString();
price = 0.0;
}

Assets::Assets(QString des, QDate dat, QString t, double p):
description(des), date(dat), type(t), price(p)
{}


void Assets::setDescription(QString des)
{
description = des;
}

QString Assets::getDescription() const
{
return description;
}

void Assets::setType(QString t)
{
type = t;
}

QString Assets::getType() const
{
return type;
}

void Assets::setDate(QDate dat)
{
date = dat;
}

QDate Assets::getDate() const
{
return date;
}

void Assets::setPrice(double p)
{
price = p;
}

double Assets::getPrice() const
{
return price;
}

QString Assets::toString() const
{
return QString("Description " + description + " Date " + date.toString("dd MMMM yyyy"));
}



here is Saving.h code


#ifndef SAVINGS_H
#define SAVINGS_H

#include "assets.h"

class Savings : public Assets
{
private:
double currentValue;
double interestRate;
public:
Savings(QString des, QDate dat, double cv, double ir);
void changeValue(double amount);
void addInterest();
double value() const;
QString toString() const;
};

#endif // SAVINGS_H

Savings.cpp code


#include "savings.h"

Savings::Savings(QString des, QDate dat, double cv, double ir)
: Assets(des, dat), currentValue(cv), interestRate(ir)
{}

void Savings::changeValue(double amount) {
currentValue += amount;
}

double Savings::value() const {
return currentValue;
}

void Savings::addInterest() {
currentValue += currentValue*interestRate/1200.0;
}

QString Savings::toString() const{
return QString("[Savings Assets] %1 \nAn amount of %2 represent Savings assets.")
.arg(Assets::toString())
.arg(currentValue)
.arg(interestRate);
}

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)
{}

jefftee
31st March 2015, 15:22
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:



Assets(QString des, QDate dat, QString t = "", double p = 0);