shadow template problem

V

Vasileios

Hello,
I have the following simple class template code:


#include "tinyvector.h"


template<class T, std::size_t M, std::size_t N>
class TinyMatrix : public TinyVector<TinyVector<T, N>, M> {
public:

// constructors
TinyMatrix() {}
TinyMatrix(T s) { assign(s); }

template<typename T, std::size_t K>
TinyMatrix<T, M, K> mult(const TinyMatrix<T, N, K>& m) const
{
TinyMatrix<T, M, K> w(0);
for(std::size_t i = 0; i < M; ++i)
for(std::size_t j = 0; j < K; ++j)
for(std::size_t k = 0; j < N; ++j)
w[j] += (*this)[k] * m[k][j];
return w;
}


};



which is included from a very simple main program:




#include <iostream>


//#include "tinymatrix.h"



using namespace std;

int main(int argc, char *argv[])
{
cout << "Hello, World!" << endl;

return 0;
}


when I compile it I get the following error (using gcc-3.72):

In file included from main.cpp:30:
testmatrix.h:12: declaration of `class T'
testmatrix.h:4: shadows template parm `class T'

gmake[3]: *** [main.o] Error 1
gmake[3]: Leaving directory `/home/user/vzografo/test/test'
gmake[2]: *** [all-recursive] Error 1
gmake[2]: Leaving directory `/home/user/vzografo/test/test'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/home/user/vzografo/test'
gmake: *** [all] Error 2
*** failed ***


Do you have any idea why I get this error? And what would be the best
way to correct it?

Thank you
Vasileios
 
R

Rob Williscroft

Vasileios wrote in
Hello,
I have the following simple class template code:


#include "tinyvector.h"

This is line 4, the T being shadowed ( <class T ... )
template<class T, std::size_t M, std::size_t N>
class TinyMatrix : public TinyVector<TinyVector<T, N>, M> {
public:

// constructors
TinyMatrix() {}
TinyMatrix(T s) { assign(s); }

This is line 12, the T doing the shadowing ( <typename T ... ),
template<typename T, std::size_t K>
TinyMatrix<T, M, K> mult(const TinyMatrix<T, N, K>& m) const
{
TinyMatrix<T, M, K> w(0);
[snip]

when I compile it I get the following error (using gcc-3.72):

In file included from main.cpp:30:
testmatrix.h:12: declaration of `class T'
testmatrix.h:4: shadows template parm `class T'

change the template < typename T ... at line 12 to say
template < typename U ... i.e. anything but T.

HTH

Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top