I am trying to port a code that should work and compile on both Linux (GCC/C++) and windows (MSVC) however the following line is giving me trouble
template <class TDerived>
struct Event
{
inline static std::string eventId = typeid(TDerived).name();
};
struct Derived : public Event<Derived>
{
Derived() = default;
};
The code uses typeid
and name()
to set the event name,
In GNU/C++ it compiles properly in both Linux and Apple (Clang), and even in Windows using MingW. but in windows using MSVC it gives the following error
error C2027: use of undefined type 'Derived'
message : see declaration of 'Derived'
message : see reference to class template instantiation 'Event<Derived>' being compiled
basically because Derived
is incomplete at this time and is not visible in the Event
scope.
But why does GNU/GCC, MingW and Clang succesfuly compiled it? Do we have a workaround in MSVC (Visual Studio)?