0

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.

2
  • Well, did you try to give it the exact signature as mentioned in the error message? Commented Feb 28, 2015 at 10:43
  • Vendor vendor(supplierName, supplierEmail, supplierIsManufacturer); what do you think this is going to do? Commented Feb 28, 2015 at 11:03

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

Comments

0

Your initializer function in Vendor needs an override that passes its parameters to setDetails

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.