I know the question is not very descriptive but I couldn’t phrase it better.
I’m trying to compile a static linked library that has several objects, all the objects contain the following:
#include foo.h
foo.h is something along these lines:
#pragma once
template<class T>
class DataT{
private:
T m_v;
public:
DataT(T v) : m_v(v){}
};
typedef DataT<double> Data;
Now, everything works fine, but if I change DataT to be just Data with double instead of T, I will get a LNK4006 warning at linking time for each .obj stating that the .ctor was already defined.
Edit 1:
#pragma once
class Data{
private:
double m_v;
public:
Data(double v) : m_v(v){}
};
Edit 2:
I’m using MSVC7.
The .ctor is actually included in both cases as in
...
public:
Data(double v);
#include foo.inl
...
//foo.inl
Data::Data(double v): m_v(v) {}
What I’m trying to accomplish though, is not to have that compiled but as a header the user can use.
I’m not sure what you’re trying to do in the example for edit #2, but I think it might help if you have the following in foo.inl:
If the contents of foo.inl is also being included in something where the
inlinekeyword won’t work or shouldn’t be, you can probably use the preprocessor to handle the difference by using a macro that expands to nothing orinlineas appropriate.