This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
vector class does not link
- To: bug-gcc at gnu dot org
- Subject: vector class does not link
- From: jochen wilhelmy <digisnap at cs dot tu-berlin dot de>
- Date: Sun, 11 Jun 2000 14:28:48 +0200
hi!
this little vector class compiles correctly, but the linker does
not find the external operator*.
please tell me if i made something wrong or if it is a gcc bug.
bye, jochen
//# gcc -v
//Reading specs from
/usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/2.96/specs
//gcc version 2.96 20000605 (experimental)
//# gcc -Wno-non-template-friend -o vectortest vectortest.cpp
//In function `main':
//(.text+0x2b): undefined reference to `operator*(Vector3<float> const
&, float)'
template <class Type>
class Vector3
{
public:
union
{
Type x;
Type u;
Type r;
};
union
{
Type y;
Type v;
Type g;
};
union
{
Type z;
Type w;
Type b;
};
Vector3();
Vector3(const Vector3<Type>&);
Vector3(Type newX, Type newY, Type newZ);
/// scalar multiplication
friend Vector3<Type> operator*(const Vector3<Type>& vector, Type
coefficient);
/// scalar division
Vector3<Type> operator/(Type coefficient) const;
};
//
template <class Type>
inline Vector3<Type>::Vector3()
{
}
template <class Type>
inline Vector3<Type>::Vector3(const Vector3<Type>& vector)
{
x = vector.x;
y = vector.y;
z = vector.z;
}
template <class Type>
inline Vector3<Type>::Vector3(Type newX, Type newY, Type newZ)
{
x = newX;
y = newY;
z = newZ;
}
template <class Type>
inline Vector3<Type> operator*(const Vector3<Type>& vector, Type
coefficient)
{
return Vector3<Type>(
vector.x*coefficient,
vector.y*coefficient,
vector.z*coefficient);
}
template <class Type>
inline Vector3<Type> Vector3<Type>::operator/(Type coefficient) const
{
return Vector3<Type>(
x/coefficient,
y/coefficient,
z/coefficient);
}
//
int main() {
Vector3<float> v;
v = v*5.0f;
v = v/5.0f;
return 0;
}