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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Maybe you're right (I'm not sure, hopefully someone can clearify this).

But how do I pass the definition of the Matrix class?
As far as I understood my second Matrix<rows,1> is just a specialization
of Matrix<rows,cols>.

My point of view is that g++ tries to pass the declaration instead of
the definition. Unfortunatelly I don't know any way of telling the
compiler to pass the _definition_ of Matrix<int,int>.

	CU
	Alexander

Oliver Kullmann wrote:
| 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
| [...]
|>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;
|>~  }
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE9/fF1dcrm1qkhaakRAhJgAKCUNUVz768crIxpUhgSdr4cUm4dYgCeNrTR
416VKCZrDThAL1oDUpBkVfI=
=73Ez
-----END PGP SIGNATURE-----


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