Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Anonymous
unregistriert
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 |
template<typename A, typename T> __forceinline const A lexical_cast(const T& source) { std::stringstream s; s << source; A destination; s >> destination; return (destination); } |
Quellcode |
|
1 2 3 4 5 6 |
__forceinline float FastSqrt (const float value) const; // [...] __forceinline float FastSqrt (const float value) const { return (ISSE implementierung); } |
Zitat
For built-in types, it doesn’t matter whether you return by value as a const, so you should avoid confusing the client programmer and leave off the const when returning a built-in type by value.
Returning by value as a const becomes important when you’re dealing with user-defined types. If a function returns a class object by value as a const, the return value of that function cannot be an lvalue (that is, it cannot be assigned to or otherwise modified).
......
Only a non-const return value can be used as an lvalue. Thus, it’s important to use const when returning an object by value if you want to prevent its use as an lvalue.
The reason const has no meaning when you’re returning a built-in type by value is that the compiler already prevents it from being an lvalue (because it’s always a value, and not a variable). Only when you’re returning objects of user-defined types by value does it become an issue.
Zitat
Any function that doesn’t modify member data should be declared as const, so it can be used with const objects.
Bei einem Konstanten Objekt, ob nun als Referenz oder als Zeiger, kann man nur Konstante Methoden aufrufen. Das macht in sofern Sinn, damit man sicherstellen kann, daß das übergebene Objekt nicht in der Funktion/Methode verändert werden kann.Zitat
const tbModell &Modell
Werbeanzeige