Probleme mit this, sehe keine lösung :(
-
Hi,
ich habe folgendes problem mit this, und ich finde keinen ausweg und auch keinen grund dafür!
naja erstmal code:
inline float vector::length (void) { return sqrtf(x*x + y*y + z*z); } inline vector vector::normalize (void) { float f = length(); vector ret = (*this); if (f != 0.0f) { ret.x /= f; ret.y /= f; ret.z /= f; } return (ret); } // [...] // benutzung: inline void matrix::rotationArbi (const vector &_vector, float value) { vector axis = _vector.normalize(); // Hier kommt der fehler?? // [...]
ich bekomme diesen Fehler:
matrix.cpp(208): error C2662: 'math::vector::normalize' : cannot convert 'this' pointer from 'const math::vector' to 'math::vector &'alles ist im namespace math. Ich benutze .NET
-
Mach mal aus
inline vector vector::normalize (void)
das:
inline vector vector::normalize (void) const
-
Um die Methode für konstante Objekte aufrufen zu können, muss die Methode selbst const sein:
//... void foo() const { }
-
klasse die rotationArbi darf net const sein weil ich innen drin werte verändere.
@interpreter
hab ich gemacht jetzt kommt der selbe fehler hier:inline vector vector::normalize (void) { float f = length(); // <<<<<<<<<<
und die length funtkion kann ich nicht auf const setzen da ich dort später mit SIMD arbeiten will und deshalb dort intern auch werte verändert werden. nämlich die W koordinate
-
Dann nimm hier:
const vector &_vector
das const weg oder änder dein Design (warum length() nicht const ist, leuchtet mir nicht ein)
-
inline float vector::length (void) { if (!useSSE) { return sqrtf(x*x + y*y + z*z); } float result = 0; w = 0.0f; // DESHALB kein const __asm { mov esi, this movups xmm0, [esi] mulps xmm0, xmm0 movaps xmm1, xmm0 shufps xmm1, xmm1, 4Eh addps xmm0, xmm1 movaps xmm1, xmm0 shufps xmm1, xmm1, 11h addps xmm0, xmm1 sqrtss xmm0, xmm0 movss result, xmm0 } w = 1.0f; // DESHALB kein const return (result); }
w = 0; oder w=1; deshalb
-
die muss aber const sein, sonst gehts nicht. Ich weiß zwar nicht was du da genau machen willst, aber du kannst Variablen als mutable deklarieren, dann kann man sie auch bei const verändern.
-
@randa:
DANKE FUNZT EINWAND FREI!!!