Jump to content
View in the app

A better way to browse. Learn more.

Next

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[RESOLU]C++ Problème de redéfinition d'un opérateu

Featured Replies

Salut

Voilà le code :

Matrix4.cpp
Vector3D Matrix4::operator*(const Vector3D& v){
return Vector3D(m[0][0]*v.getX() + m[0][1]*v.getY() + m[0][2]*v.getZ(),
				m[1][0]*v.getX() + m[1][1]*v.getY() + m[1][2]*v.getZ(),
				m[2][0]*v.getX() + m[2][1]*v.getY() + m[2][2]*v.getZ());
}

-----------------------
Vector3D.hpp:
inline float getX(){return values[V3D_x];}
inline float getY(){return values[V3D_y];}
inline float getZ(){return values[V3D_z];}

Si j'enlève le const, ça compile. Sinon "error: passing 'const Vector3D ' as `this' argument of `float Vector3D::getX()' discards qualifiers".

Est-ce parce que j'appelle une fonction sur un paramètre constant?

Si oui, comment je peux faire pour définir ma méthode en gardant le caractère constant de Vector3D?

Merci.

Edited by serik

Vector3D.hpp:
inline float getX() const {return values[V3D_x];}
inline float getY() const {return values[V3D_y];}
inline float getZ() const {return values[V3D_z];} 

N'engage que moi :vomi2:

D'ailleurs, je serais toi, je rajouterais des const un peu partout, il en vaut mieux plus que pas assez.

Vector3D.hpp:
inline const float getX() const {return values[V3D_x];}
inline const float getY() const {return values[V3D_y];}
inline const float getZ() const {return values[V3D_z];} 

Spaz001 a raison.

Tu utilises un const Vector3D& v

v est donc constant. Tu dois appeler les méthodes constantes de cet objet. donc getX() & co doivent être constantes.

D'où le

inline float getX() const {return values[V3D_x];}

Ensuite, tu peux aussi retourner un float constant... rien ne t'en empêche.... mais ce n'est pas primordial.

  • Author

ok merci du tuyau je ne savais pas qu'on pouvais trouver autant de const!

j'ai fait beaucoup de C et peu de C++...

Archived

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.