I've searched for a long time and didn't find any answers to my problem (even though I tried to apply some techniques i found). Here's the issue:
I am supposed to create a template that takes 2 arguments : and integer and and object (instance of another template). Even though this template class inherits from other templates, I think those classes aren't part of the issue. So here's the code:
template <typename Type, const ConPol<Type>& Div>
class ModPol : public Pol<Type>, public VecF<Type, Div.size()>{
private:
//
protected:
//
public:
// constructors & destructor
ModPol()
virtual ~ModPol();
};
When I try to call this particular class, I use these lines :
const ConPol<int> poly;
ModPol<int, &poly> modpoly;
Unfortunately, I get this error:
error: non-type template argument refers to object 'poly' that does not have linkage
I would like to know how to be able to instantiate my template class. Don't hesitate to explain with simple words (I think of myself as a beginner).
Cheers !
When you declare a global object in C++ that is const
then by default it has internal linkage. What that means is that the object is unrelated to any object with the same name and type in other source files.
But there's a rule that if you pass a reference to an object as a template parameter then it must have external linkage - i.e. be a name that refers to exactly the same object no matter which file it is used in.
So poly
isn't allowed because it is const
and so has internal linkage.
The solution is to override the default and say you want poly
to have external linkage:
extern const ConPol<int> poly;