WTF?? compiler weirdness (MSVC)

Started by
2 comments, last by Sandman 22 years, 4 months ago
I have a function in my simple camera class called ''translate camera. It takes a matrix and multiplies the position vector by the appropriate matrix.
  
void CCamera::TranslateCamera(const matrix4f& m)
{
	position *= m;
}
  
simple huh? Unfortunately, this doesn''t compile, reporting the following error:

d:\software\microsoft visual studio 6\msdev98\myprojects\game\game\cvector.h(319) : error C2676: binary ''['' : ''const class matrix4'' does not define this operator or a conversion to a type acceptable to the predefined operator
        D:\Software\Microsoft Visual Studio 6\MSDev98\MyProjects\game\game\ccamera.cpp(53) : see reference to function template instantiation ''class vector3 &__thiscall vector3::operator *=(const class matrix4)'' being compiled
d:\software\microsoft visual studio 6\msdev98\myprojects\game\game\cvector.h(321) : error C2676: binary ''['' : ''const class matrix4'' does not define this operator or a conversion to a type acceptable to the predefined operator
        D:\Software\Microsoft Visual Studio 6\MSDev98\MyProjects\game\game\ccamera.cpp(53) : see reference to function template instantiation ''class vector3 &__thiscall vector3::operator *=(const class matrix4)'' being compiled
 
However, this does compile, and works perfectly:
  
void CCamera::TranslateCamera(const matrix4f& m)
{
	m;
	position *= m;
}
  
WTF is going on here?
Advertisement
does the vector class have the following memper operator?

void operator *=(const matrix4&);

if not that is why the first example is failing

as to why the second version succeeds - not entirely sure

This may be a silly question, but there aren''t any data members in CCamera called ''m'' are there?

Yes, and no.

The only thing I can think of is that somehow referring to the matrix causes the compiler to realise that it actually has to compile the matrix4f template, but without it it doesn''t bother for some reason.

Its confused me anyway.
Fixed it!

My definition of the *= operator read:

  template <class X>vector3<T>& operator *=(const matrix4<X> lhs)  


changing it to

  template <class X>vector3<T>& operator *=(const matrix4<X>& lhs)  


stopped the problem. No idea why it should happen in the first place though, something weird to do with references.

This topic is closed to new replies.

Advertisement