Inline enum reflection causes linker error
Hi!
Could you advice what am I doing wrong?
Here's the header file:
And here's what I get from the linker:
Could you advice what am I doing wrong?
Here's the header file:
Code: Select all
namespace Test
{
enum class TestEnum
{
A = 0,
B = 1
};
}
NS_IMPLEMENT_INLINE_REFLECTION_ENUM(Test::TestEnum)
{
NsVal("A", Test::TestEnum::A);
NsVal("B", Test::TestEnum::B);
}
Enums work without an issue if I separate their declaration and implementation, but I'd like to use NS_IMPLEMENT_INLINE_REFLECTION_ENUM to keep them in one place.error LNK2005: "public: static void __cdecl Noesis::TypeEnumFiller<enum Test::TestEnum>::Fill(class Noesis::TypeEnumCreator<enum Test::TestEnum> &)" (?Fill@?$TypeEnumFiller@W4TestEnum@Test@@@Noesis@@SAXAEAV?$TypeEnumCreator@W4TestEnum@Test@@@2@@Z) already defined in ***.obj
error LNK2005: "public: static class Noesis::TypeEnum const * __cdecl Noesis::TypeEnumFiller<enum Test::TestEnum>::GetType(void)" (?GetType@?$TypeEnumFiller@W4TestEnum@Test@@@Noesis@@SAPEBVTypeEnum@2@XZ) already defined in ***.obj
Re: Inline enum reflection causes linker error
It seems there is a problem when using that macro in headers included more than once. The following patch fixes the problem:
Could you please report this in the tracker?
Code: Select all
Index: ReflectionImplementEnum.h
===================================================================
--- ReflectionImplementEnum.h (revision 11568)
+++ ReflectionImplementEnum.h (working copy)
@@ -41,11 +41,11 @@
///
////////////////////////////////////////////////////////////////////////////////////////////////////
#define NS_IMPLEMENT_REFLECTION_ENUM2(T, name) \
- const Noesis::TypeEnum* Noesis::TypeEnumFiller<T>::GetType() \
+ inline const Noesis::TypeEnum* Noesis::TypeEnumFiller<T>::GetType() \
{ \
return Noesis::TypeEnumHelper<T>::GetType(name); \
} \
- void Noesis::TypeEnumFiller<T>::Fill(Noesis::TypeEnumCreator<T>& helper)
+ inline void Noesis::TypeEnumFiller<T>::Fill(Noesis::TypeEnumCreator<T>& helper)
#define NS_IMPLEMENT_REFLECTION_ENUM1(T) NS_IMPLEMENT_REFLECTION_ENUM2(T, #T)
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest