I'm designing a class hierarchy that follows a diamond pattern, and I'm trying to debug through about a million errors right now; however, most of them are simple fixes that I should be able to figure out. However, I'm having difficulty understanding the compiler's complaints in this one.
Basically, I start off with a simple Entity class that has two derived classes: Buyer and Seller. A fourth class Retailer, in turn, is descended from both classes - that is, it uses multiple inheritance(and yes, I know what kind of mess that's asking for, unfortunately that's exactly the point of the project).
for reference, the header files for my classes is as follows:
Entity.h
#pragma once
#include <string>
class Entity {
public:
Entity(std::string &, std::string &, double);
/*Accessor methods for private members*/
std::string getName();
std::string getID();
double getBalance();
/*Mutator methods for private members*/
void setName(std::string &);
void setID(std::string &);
void setBalance(double);
/*Additional methods*/
virtual void list();
virtual void step() = 0;
protected:
/*Private members of the entity class*/
std::string name;
std::string id;
double balance;
};
for the Buyer.h
file
#pragma once
#include "Entity.h"
#include "Order.h"
#include "Seller.h"
#include <queue>
#include <string>
class Seller;
class Buyer : virtual public Entity {
public:
Buyer(std::string, std:: string, double);
virtual ~Buyer() { }
void addSeller(Seller *);
std::queue<Seller *> getSellers();
void addOrder(Order *);
void list();
void step() override;
protected:
std::queue<Order *> orders;
std::queue<Seller *> sellers;
};
For Seller.h
#pragma once
#include "Entity.h"
#include "Order.h"
#include "Buyer.h"
#include "Inventory.h"
#include <string>
#include <vector>
class Buyer;
class Seller : virtual public Entity {
public:
Seller(std::string, std::string, double);
virtual ~Seller() {}
void addBuyer(Buyer *);
std::vector<Buyer> getBuyers();
void setInventory(Inventory *);
Inventory * getInventory();
void list();
double fillOrder(Order *);
void step();
protected:
Inventory inventory;
std::vector<Buyer *> buyers;
};
And finally for Retailer.h
#pragma once
#include "Buyer.h"
#include "Seller.h"
#include <string>
class Retailer : public Buyer, public Seller {
public:
Retailer(std::string, std::string, double);
virtual ~Retailer() { }
void list();
void step();
};
The majority of the errors I get when trying to compile these files are along the lines of
Buyer.h:9:7: note: candidate expects 1 argument, 0 provided
Seller.h:14:3: note: candidate expects 3 arguments, 0 provided
Which is odd, because for that first line, I shouldn't even have to provide an argument and the second one is the definition of the constructor....
Basically, what I'm failing to understand is what does the compiler mean by a line of code expecting a different number of arguments than were provided? Should I be including default constructors that use no arguments? Is there something wrong with the way they're declared? I can also post the code for my .cpp files if necessary, although they don't seem to be mentioned a lot by the compiler error reports.
It means that the compiler is considering that function for overload resolution, but it's not a match because of differing number of arguments.