我是C ++的初学者。我在Visual Studio 2019(C ++ 17)中研究它,我已经在.h文件中定义了一个类,但是在另一个.h文件中我无法使用它

史蒂夫·威尔逊

有一些编码实践代码,class ebb_detial_item是一个表示包含一些信息的对象的类。当用户在命令窗口中输入常规内容时,将创建该类别,然后程序会将其分类为正确的category(class category),类别的指针是该类别的成员。该类别具有一个列表,用于存储指向分类为该类别的成员的指针。这是一个循环引用,但我认为这不是由循环引用引起的错误。

Categories_tbl.h

#ifndef CATEGORIES_TBL
#define CATEGORIES_TBL

#include <memory>
#include <vector>
#include <list>
#include "ebb_string.h"
#include "ebb_detial_itme.h"

namespace ebb_impl
{
    class ebb_detial_item;

    namespace
    {
        std::vector<unsigned> default_rev_dates{
            0,    1,    2,    4,    7,
            10,   15,   16,   30,   31,
            90,   91,   150,  151,  152,
            210,  211,  270,  272,  360,
            370,  480,  490,  720,  750,
            1080, 1180, 1440
        };
    }

    class category
    {
    private:
        friend class ebb_detial_item;

        my_ebbstring::ebb_string name{};
        std::list<std::unique_ptr<ebb_impl::ebb_detial_item>> ebbtbl;
        my_utility::id_pool::id_pool<unsigned> item_id_pool;

        std::vector<unsigned>* rev_dates_ptr{ &default_rev_dates };

    public:
        category(my_ebbstring::ebb_string name)
            : name{ name }, item_id_pool{ name } {   }

        category& add(ebb_detial_item* item_ptr);
        category& remove(ebb_detial_item* item_ptr);

        void set_rev_dates(const std::vector<unsigned>& new_plan);
    };
}

#endif

ebb_detial_itme.h

#ifndef EBB_DETIAL_ITEM_H
#define EBB_DETIAL_ITEM_H

#include "ebb_string.h"
#include "my_utility.h"
#include "DateTime.h"
#include "categories_tbl.h"
#include <chrono>
#include <list>

namespace ebb_impl
{
    class ebb_detial_item
    {
    private:
        unsigned item_id{ 0U };
        my_ebbstring::ebb_string content;
        my_ebbstring::ebb_string materials_address;
        my_datetime::DateTime creat_date{};
        unsigned review_times{};
        std::unique_ptr<category> cate_ptr;
 //                     ^~~~~~~~
 //         error1      C2065   'category': undeclared identifier
 //         error2      C2923   'std::unique_ptr': 'category' is not a valid template type argument for parameter '_Ty' 



    public:
        ebb_detial_item(
            my_ebbstring::ebb_string c, 
            category* category_ptr,
 //         ^~~~~~~~
 // error3  C2061   syntax error: identifier 'category' 


            my_datetime::DateTime creat_date,
            my_ebbstring::ebb_string materials_address = ""
        )
            : content{ c }, materials_address{ materials_address }, 
              cate_ptr{ category_ptr}, creat_date{ creat_date }
        {
            item_id = cate_ptr->item_id_pool.next_id();
        }

        bool need_review() const;
        bool need_review(my_datetime::DateTime day) const;

        my_ebbstring::ebb_string get_category() const;
        my_ebbstring::ebb_string get_content() const;
        void set_materials(const my_ebbstring::ebb_string& add);
        void open_materials() const;

        my_ebbstring::ebb_string to_string() const;
    };
}

#endif

我无法完全理解这些错误。也许名称空间使用不正确?

我还没有列出一些错误,所有错误都是关于的category错误清单

新浪劳菲

categories_tbl.h头,你包括ebb_detial_itme.h头和ebb_detial_itme.h头,你包括categories_tbl.h header.This是电话通知包含!您必须删除其中之一。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章