gpt4 book ai didi

c++ - 没有调用正确的构造函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:29:11 25 4
gpt4 key购买 nike

<分区>

这是我的标题:

//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

我的.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();
}
}

编译错误:

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&)

从错误来看,它似乎调用了零参数构造函数而不是采用字符串的构造函数。我构建的日期类显然没有零参数构造函数。

几个小时以来,我一直在努力解决这个问题,如有任何帮助,我们将不胜感激。在一个类似的问题中,我被告知要查找成员初始值设定项列表。我猜我已经并且不太了解如何正确实现它,因为它似乎无法解决问题。

学期刚开始几周,这是我的第一堂 C++ 课,放轻松 :)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com