Вот мой минимальный код:
base.h
Код: Выделить всё
#ifndef BASE_H
#define BASE_H
#include
class IBase {
public:
virtual ~IBase() = default;
};
template
class Base : public IBase {
public:
static constexpr std::string_view TYPE_ID = Derived::TYPE_ID;
};
#endif
Код: Выделить всё
#include
#include "base.h"
class Derived : public Base {
public:
static constexpr std::string_view TYPE_ID = "Derived";
};
int main() {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79337869/why-does-accessing-a-static-member-of-the-derived-type-in-crtp-work-with-g-but[/url]