File F1.h is
enum class E { A, B, C };
template<class E> class X {
public: X(const E& y) { self.z = y; }
};
__declspec(dllexport) X<E> foo; // Attempt to declare but not instantiate
File F1.cpp is
#include <F1.h>
__declspec(dllexport) X<E> foo(E.A); // Attempt to instantiate matching .H declaration
File F2.cpp is
#include <F1.h>
void f()
{
E z = foo.z; // Attempt to use from declaration without instantiating
}
A Visual Studio C++ project P has F1.cpp and F2.cpp. Building this project gives LNK2005 error that foo in F1.obj is already defined in F2.obj.
Is there a way to set this up so that foo is exported in P.DLL from F1.obj and is available in F2.cpp and is not defined in F2.obj?