Forward declaration problem: incomplete type of "enumeration :: Category" used in the naming specifier

I want to have a wrapper around an enumeration that will give me the ability to convert it to a string and vice versa.

The base class is as follows:

template<typename TEnum>
class StringConvertedEnum {
public:
    static std::string toString(TEnum e);

    static TEnum toEnum(std::string &str);

protected:
    static const std::map<std::string, TEnum> _stringMapping;
    static const std::map<TEnum, std::string> _enumMapping;
};

And then I want to have something like this:

class Category : public StringConvertedEnum<Category::Enum> {
public:
     enum Enum {
          Category1,
          Category2,
          OTHER
     };
};

However, at the moment it is not compiled with this error:

incomplete type 'enums::Category' used in nested name specifier

How to solve this problem?

+4
source share
1 answer

Enum , , , Category StringConvertedEnum. , . "3.3.2 [basic.scope.pdecl]" ( AndyG ).

- Enum Category:

enum Enum {
    Category1,
    Category2,
    OTHER
};

class Category : public StringConvertedEnum<Enum> {};

Zen of Python, ++:

, .

- :

class BaseCategory {
public:
    enum Enum {
        Category1,
        Category2,
        OTHER
    };
};
class Category : public BaseCategory, public StringConvertedEnum<BaseCategory::Enum> {};

, , ++.

+4

Source: https://habr.com/ru/post/1661209/


All Articles