template class Problem
-
What a perfect world it could be with out errors. Going forth in a software developement I got to an error which I could not find a resource that give an answer. It's about templates, and I must tell you that I'm new in this stuff. Consider 'ClassA' which requiers template list when you want to define a object of it. Like this:
ClassA<long> obj;
And Consider another class that is the same to the previous one, 'ClassB' (with template list). Now here's the problem, how can you define an object of 'ClassA' with the template list of 'ClassB' type, it should be something like this:ClassA<ClassB> obj;
But compiler tells me that it has an error becuase 'ClassB' requiers a list of templates. So I thought that it might be defined like this:ClassA<ClassB<long>> obj;
Now it has an another error: error C2146: syntax error : missing ',' before identifier 'obj' Well how can I define an object from a class with template list of sort of a class with template list? -
What a perfect world it could be with out errors. Going forth in a software developement I got to an error which I could not find a resource that give an answer. It's about templates, and I must tell you that I'm new in this stuff. Consider 'ClassA' which requiers template list when you want to define a object of it. Like this:
ClassA<long> obj;
And Consider another class that is the same to the previous one, 'ClassB' (with template list). Now here's the problem, how can you define an object of 'ClassA' with the template list of 'ClassB' type, it should be something like this:ClassA<ClassB> obj;
But compiler tells me that it has an error becuase 'ClassB' requiers a list of templates. So I thought that it might be defined like this:ClassA<ClassB<long>> obj;
Now it has an another error: error C2146: syntax error : missing ',' before identifier 'obj' Well how can I define an object from a class with template list of sort of a class with template list?Hi The solution is pretty simple. In stead of ClassA> obj; use ClassA > obj; Yes, the only difference is a space. The reason for the error is that the compiler finds '>>' and believes it to be the >> operator instead of the end of the template lists. So if you put in a space, the first > will end the inner template list and the second the outer and the compiler is happy.