Implicit template argument deduction

May 11, 2013 at 6:55am
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...
}
Last edited on May 11, 2013 at 6:56am
May 11, 2013 at 10:54am
Try changing:
list<list<double>> toreturn; to
list< list<double> > toreturn; and other similar occurences.
Last edited on May 11, 2013 at 10:56am
May 11, 2013 at 11:01am
JockX wrote:
Try changing:
list<list<double>> toreturn; to list< list<double> > toreturn; and other similar occurences.

The arrangement does not matter in C++11, the error has to do with the return type.
May 11, 2013 at 5:34pm
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.
May 11, 2013 at 6:54pm
closed account (zb0S216C)
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template< typename Container_Type >
class MATRIX
{
  public:
    MATRIX( Container_Type const &Container );

    Vectors::MATRIX< Container_Type > Splice( unsigned Column );
};

template< typename Container_Type >
Vectors::MATRIX< Container_Type > Vectors::MATRIX< Container_Type >::Splice( unsigned Column )
{
  std::list< std::list< double > > To_Return;
  return( To_Return );
}

Wazzak
Last edited on May 11, 2013 at 6:55pm
May 11, 2013 at 8:04pm
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.

Am I calling the function correctly?
Last edited on May 11, 2013 at 8:09pm
Topic archived. No new replies allowed.