There are some codding practice code, class ebb_detial_item is a class to represents an object that contain some information. it will be created when user input something regular at command window, then The program will classify it into the correct category(class category), and the pointer of the category is a member of it. That category has a list to store pointers to members classified as that category. It is a circular reference, but I think it's not a bug caused by circular references.
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
I can't understand all about those error. Maybe the name space is used incorrectly?
There are still some errors that I haven’t listed, bug all of them is about category.
