M
Martin Magnusson
I have gotten myself all tangled up in templated classes and can't quite
see what to do right now. GCC 3.3.1 give me an error saying
test.cpp: In constructor `Vertex<N>::Vertex(A::Vector<N, float>) [with
int N = 3]':
test.cpp:55: error: invalid use of `template<int N, class T> class
A::Vector'
I suspect that it has something to do with the default argument of
Vertex's constructor. It works better if I define a default constructor
without arguments.
I hope that someone of you has the time to take a look at this and see
if you can find what's wrong. I've tried to cut the code below down to a
minimum.
/// Begin file test.cpp //////////////////////////////////////////////
#include <iostream>
using namespace std;
namespace A
{
template< int N, typename T >
class Vector
{
public:
Vector( int value )
{
i = value + N;
}
int i;
};
typedef Vector< 3, float > Vector3d;
template< int N, typename T >
class Compare
{
public:
bool operator () ( const Vector< N, T >& lhs, const Vector< N, T >&
rhs )
{
return lhs.i < rhs.i;
}
};
}
template< int N >
class Vertex
{
public:
Vertex( A::Vector<N,float> position = A::Vector( 0 ) );//Something
wrong here?
class Compare
{
public:
bool operator () ( const Vertex< N >& lhs, const Vertex< N >& rhs )
{
return A::Compare< N, float >( lhs.v, rhs.v );
}
};
A::Vector<N,float> v;
};
typedef Vertex<3> Vertex3d;
int main()
{
Vertex<3> vert1;
cout << vert1.v.i; // Error on this line!
return 0;
}
/// End file test.cpp ////////////////////////////////////////////////
see what to do right now. GCC 3.3.1 give me an error saying
test.cpp: In constructor `Vertex<N>::Vertex(A::Vector<N, float>) [with
int N = 3]':
test.cpp:55: error: invalid use of `template<int N, class T> class
A::Vector'
I suspect that it has something to do with the default argument of
Vertex's constructor. It works better if I define a default constructor
without arguments.
I hope that someone of you has the time to take a look at this and see
if you can find what's wrong. I've tried to cut the code below down to a
minimum.
/// Begin file test.cpp //////////////////////////////////////////////
#include <iostream>
using namespace std;
namespace A
{
template< int N, typename T >
class Vector
{
public:
Vector( int value )
{
i = value + N;
}
int i;
};
typedef Vector< 3, float > Vector3d;
template< int N, typename T >
class Compare
{
public:
bool operator () ( const Vector< N, T >& lhs, const Vector< N, T >&
rhs )
{
return lhs.i < rhs.i;
}
};
}
template< int N >
class Vertex
{
public:
Vertex( A::Vector<N,float> position = A::Vector( 0 ) );//Something
wrong here?
class Compare
{
public:
bool operator () ( const Vertex< N >& lhs, const Vertex< N >& rhs )
{
return A::Compare< N, float >( lhs.v, rhs.v );
}
};
A::Vector<N,float> v;
};
typedef Vertex<3> Vertex3d;
int main()
{
Vertex<3> vert1;
cout << vert1.v.i; // Error on this line!
return 0;
}
/// End file test.cpp ////////////////////////////////////////////////