I'm trying to build a matrix class that can take various containers for its parameters via templates. Unfortunately, when I try to compile the code below, my compiler is telling me that I am passing two template arguments instead of one. This occurs specifically on line 59 when I return a list<list<double>> and call the MATRIX constructor. I appreciate any help.
Some extra information to clarify the code below:
-Vectors is a namespace
-MATRIX is a class and the two functions below are its member functions
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
//Matrix splicer
Vectors::MATRIX Vectors::MATRIX::Splice(unsigned column){
list<list<double>> toreturn;
//...Splice Matrix and store that in toreturn...
return toreturn;
}
//Constructor template
template<
typename primitive,
template<typename> class IContain,
template<typename> class Contain
>
Vectors::MATRIX::MATRIX(const Contain<IContain<primitive>>& c___){
//Initialize member variable...
}
Matri X is right. Whitespace is ignored by the compiler.
But I still need help. I tried toying around with template<typename=primitive> class IContain; or template<template<typename> class IContain> class Contain, removing the second template parameter of my constructor, but I always get the same error...
I've never worked with template template parameters before, so this is all very confuzzling to me.
I don't think you need all of those template-parameters for "Vectors::MATRIX". I don't know how you've implemented the rest of "Vectors::MATRIX", but a single template-parameter would suffice as far as I can see. Try this:
Thanks! Templating the entire class worked though now my code has more template keywords than I'd like. However, now I face a new problem. Another function I have creates an instance of MATRIX, so I had to make it a template. However, the compiler isn't able to deduce/substitute the parameter when I try to use it...
Information to clarify code below:
-VectorData is another class storing vectors for analyses
-Cross is a non-member function that returns a VectorData instance
Here's my Cross function:
1 2 3 4 5 6 7 8
//Using initializer_list parameter because I haven't abstracted everything yet
template<template<typename> class Contain>
Vectors::VectorData Vectors::Cross(const initializer_list<Vectors::VectorData>& veclist){
//Conversion stuff
//Instantiation of MATRIX object
MATRIX<Contain> catalyst(vectorlist);
//Find determinants and return new vector
}
Cross function call:
1 2 3
//main function; Assignment and Comparison are VectorData instances
Comparison = Cross<list<double>>({Assignment,Comparison});
//I have also tried "Cross<list>" but that did not work as well
I would like to note that before I started converting things to templates, the Cross function worked fine and the templation is the only change to it.