Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I am trying to build a class template who is supposed to take an instance of another class template as parameter. Here's the idea :

Rough idea of the call in main():
C++
const aClassTemplate<type> templateObjectName;
otherClassTemplate<type,> secondTemplateObjectName;

My .hpp declares the template with this line :

C++
template <typename Type, const aClassTemplate<Type>& NameOfInstance>

The problem is that this doesn't seem to work. Even when compiling i get a 'linkage error', does anyone know how to do this properly ?

As asked, compliant code of actual class (content doesn't matter) :

C++
template <typename Type, const ConPol<Type>& Div>
class ModPol : public Pol<Type>, public VectFix<Type, Div.size()>{
private:
    //
    
protected:
    //
    
public:
    // constructors & destructor
    ModPol();                                  
    virtual ~ModPol();
    
};


Call in main():

C++
const ConPol<int> poly;
ModPol<int, &poly> modpoly;


Actual error:

error: non-type template argument refers to object 'poly'
that does not have linkage
Posted
Updated 14-Nov-15 3:51am
v4
Comments
[no name] 13-Nov-15 15:08pm    
Post compilable code that demonstrates the problem.
Member 12137831 14-Nov-15 8:30am    
I edited my code, I hope it's enough to understand the issue
[no name] 14-Nov-15 4:53am    
A snippet of your code would help along with the actual error. This seems to address the linker error - you need to declare the type. http://stackoverflow.com/questions/9843671/c-template-function-taking-template-class-as-parameter
Member 12137831 14-Nov-15 8:30am    
Code inserted
Member 12137831 14-Nov-15 10:21am    
PS : I declared my type (it's a template), that's why I create poly of that type. No ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900