Archived

This topic is now archived and is closed to further replies.

WTF?? compiler weirdness (MSVC)

This topic is 5815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites