c++ - 错误 : has no member named ‘current_date’

标签 c++

<分区>

所以我有这个仓库类:

仓库.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;
        std::map<std::string, a4::food> items;
        dates current_date;
        void next_day();
 };
}
 #endif

仓库.cc:

#include "warehouse.h"
#include "dates.h"
namespace a4
{
 //constructor
 warehouse::warehouse(std::string name, std::string start_date)
 {
     this->current_date = new dates(start_date);
 }
 void warehouse::next_day()
 {
     this->current_date.next_day();
 }
}

我得到的编译器错误是:

warehouse.cc: In constructor ‘a4::warehouse::warehouse(std::string, std::string)’:
warehouse.cc:8: error: ‘class a4::warehouse’ has no member named ‘current_date’
warehouse.cc: In member function ‘void a4::warehouse::next_day()’:
warehouse.cc:12: error: ‘class a4::warehouse’ has no member named ‘current_date’

知道为什么它不能将 current_date 识别为成员吗?它可能非常简单,但我学习 C++ 才几周时间。

最佳答案

我能看到的唯一可能性是这不是您的 header 的样子。确保您一直在正确的目录中编辑正确的文件。

修复该问题后,您会发现下一个错误是“无法将 dates* 转换为 date”。这是因为您在不应该使用的地方使用 new

关于c++ - 错误 : has no member named ‘current_date’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14614158/

相关文章:

c++ - GNU make 一种双冒号

c++ - 是否有迭代 POSIX 环境变量的函数?

c# - 如何计算 Box2D/Farseer 中夹具和点之间的距离?

c++ - 让 svn diff 在提交期间显示 C++ 函数

c++ - 如何有效地将 vector<pair<int,int>> 转换为 multimap<int,int>?

java - 链表如何在不使用指针的情况下实现?

c++ - DirectDraw使用GetProcAddress获取程序地址

c++ - 使用 win32 C++ 和 Hook 从应用程序中的按钮获取文本

c++ - 合并排序不正确的输出

c++ - 在链表中存储数组元素