Reputation: 10608
I've been working on a Qt Assignment and I've completed the whole task but I can't seem to fix one final bug that won't let my program run.
The error is:
no matching function for call to 'Vendor::Vendor(QString&, QString&, bool&)'
Vendor supplierInfo(supplierNmae,supplierEmail,supplierIsManufacturer);
line 41 ^
It consist of two classes but only my vendor class and main class is affected by the error.
Here is the code to my main.cpp:
#include <QCoreApplication>
#include "vendor.h"
#include "product.h"
#include <QString>
#include <QTextStream>
QTextStream cout(stdout);
QTextStream cin(stdin);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//Declare variables
QString productName;
double productPrice;
QString supplierName;
QString supplierEmail;
QString supplierIsManufacturerStr;
bool supplierIsManufacturer;
//Get user input
cout << "Enter the product name:\t";
productName = cin.readLine();
cout << "Enter the product price:\tR";
cin >> productPrice;
cout << "Enter the supplier name:\t";
supplierName = cin.readLine();
cout << "Enter the supplier email:\t";
cin >> supplierEmail;
cout <<"Is the supplier a manufacturer:\t";
cin >> supplierIsManufacturerStr;
if(supplierIsManufacturerStr.at(0).toLower() == 'y') {
supplierIsManufacturer = true;
} else {
supplierIsManufacturer = false;
}
//Implement classes
Vendor vendor(supplierName, supplierEmail, supplierIsManufacturer);
Product product(productName, productPrice, vendor);
product.setSupplier(supplierName, supplierEmail, supplierIsManufacturer);
product.toString(supplierIsManufacturer);
return a.exec();
}
And here's the code to my vendor.h file:
#ifndef VENDOR_H
#define VENDOR_H
#include <QString>
class Vendor {
public:
Vendor();
void setDetails(QString name, QString email, bool isManufacturer);
bool isManufacturer();
QString getName();
QString toString();
private:
QString m_Name;
QString m_Email;
bool m_IsManufacturer;
};
#endif // VENDOR_H
I'm still getting back into the zone regarding using classes so I'm quite out of practice and would appreciate any help I could get on this. Thank you in advance.
Upvotes: 0
Views: 839
Reputation: 965
Your initializer function in Vendor needs an override that passes its parameters to setDetails
Upvotes: 0
Reputation: 468
The Vendor
class is missing a constructor matching the line in main.cpp.
Either implement the constructor:
// Vendor.h
class Vendor {
public:
Vendor();
Vendor(const QString& name, const QString& email, bool isManufacturer);
...
// Vendor.cpp
Vendor::Vendor(const QString& name, const QString& email, bool isManufacturer)
: m_Name(name), m_Email(email), m_IsManufacturer(isManufacturer)
{}
Or use the existing setDetails
function:
Vendor vendor;
vendor.setDetails(supplierName, supplierEmail, supplierIsManufacturer);
Upvotes: 1