This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problems with template template parameter
- From: Oliver Kullmann <O dot Kullmann at Swansea dot ac dot uk>
- To: Alexander Helm <helm at fs dot tum dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 16 Dec 2002 15:17:20 +0000
- Subject: Re: Problems with template template parameter
- References: <3DFCD26A.9060901@fs.tum.de>
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-----