So here is my header:
//warehouse.h
#ifndef WAREHOUSE_H
#define WAREHOUSE_H
#include<string>
#include<map>
#include "dates.h"
namespace a4
{
class warehouse
{
public:
warehouse(std::string name, std::string start_date);
private:
std::string name;
std::string busiest_day;
int most_transactions;
dates current_date;
std::map<std::string, a4::food> items;
void next_day();
};
}
#endif
My .cc:
//warehouse.cc
#include "warehouse.h"
#include "dates.h"
namespace a4
{
//constructor
warehouse::warehouse(std::string wname, std::string start_date)
{
wname = name;
current_date = dates(start_date);
}
void warehouse::next_day()
{
current_date.next_day();
}
}
And the compiler error:
warehouse.cc: In constructor ‘a4::warehouse::warehouse(std::string, std::string)’:
warehouse.cc:6: error: no matching function for call to ‘a4::dates::dates()’
dates.h:10: note: candidates are: a4::dates::dates(std::string)
dates.h:8: note: a4::dates::dates(const a4::dates&)
From the error it looks like its calling a zero argument constructor instead of the constructor that takes a string. The dates class i built doesn’t have a zero argument constructor obviously.
Ive been trying to figure this out for hours any help would be appreciated. In a similar question I was told to look up member initializer lists. I have and don’t really understand how to implement it right I guess, cause it doesn’t seem to solve the problem.
Were only a few weeks into the semester and this is my first class on c++, go easy on me 🙂
It’s because you have
dates current_date;as a member ofwarhouse. Whenwarhouse‘s constructor is called, the default constructors of all its member variables will be called. You can change the constructors any member variables use with:notation (creating an initializer list):Or by simply defining a blank constructor for
dates.