This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problems with template template parameter


Hi,

your case looks pretty clear to me: The template template parameter C
for the class template Matrix_Base has two parameters, while for the
specialisation

template<int rows>
class Matrix<rows,1> : public Matrix_Base<rows,1,Matrix>

you supply it with an actual parameter, which in this context
has only one template parameter.

As far as I know, the Standard demands that the number of template
template parameter must exactly match. Thus I guess that version 2.95
was simply too sloppy.

Oliver 

> Hi,
> 
> I'm sorry, I don't know if it's a bug or just my fault. If I compile the
> following code with g++-2.95 everything is fine. Version 3.2.1 complaints.
> 
> 
> The code:
> 
> ~  #include <iostream>
> 
> ~  using namespace std;
> 
> ~  template<int rows, int cols, template<int rows, int cols> class C>
> ~    class Matrix_Base {
> ~      public:
> ~        Matrix_Base() {
> ~          cout << __PRETTY_FUNCTION__ << endl;
> ~        };
> ~        template<int cols2>
> ~          C<rows,cols2>* operator*(C<cols,cols2>& lhs) {
> ~            return 0;
> ~          }
> ~    };
> 
> ~  template<int rows, int cols>
> ~    class Matrix : public Matrix_Base<rows,cols,Matrix> {
> ~      public:
> ~        Matrix() : Matrix_Base<rows,cols,Matrix>() {
> ~          cout << __PRETTY_FUNCTION__ << endl;
> ~        };
> ~      };
> 
> ~  template<int rows>
> ~    class Matrix<rows,1> : public Matrix_Base<rows,1,Matrix> {
> ~      public:
> ~        Matrix() : Matrix_Base<rows,1,Matrix>() {
> ~          cout << __PRETTY_FUNCTION__ << endl;
> ~        };
> ~    };
> 
> ~  int main (int argc, char **argv) {
> ~    Matrix<2,2> A;
> ~    Matrix<2,1> B;
> 
> ~    A*A;
> ~  }
> 
> The error message of g++ (3.2.1):
> 
> ~  test2.cc: In constructor `Matrix<rows, 1>::Matrix()':
> ~  test2.cc:29: type/value mismatch at argument 3 in template parameter
> ~  list for `template<int rows, int cols, template<int rows, int cols>
> ~  class C> class Matrix_Base'
> ~  test2.cc:29:   expected a class template, got `Matrix<rows, 1>'
> ~  test2.cc:29: class `Matrix<rows, 1>' does not have any field named `
> ~  <declaration error>'
> ~  test2.cc: In function `int main(int, char**)':
> ~  test2.cc:36: warning: unused variable `Matrix<2, 1> B'
> 
> 
> Any help will be appreciated.
> 
> 	Thanks in advance
> 	Alexander
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.0 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQE9/NJgdcrm1qkhaakRAh5UAJ0V7cWRSe3B8Uj5KAF0dF4UaFlUUACggHgx
> q8qP7BoAq/KXh33rQ5T1ApI=
> =5h09
> -----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]