void DoSomething(float f)
{
//some operation on f
}
void Foo
{
Scalar x = 50.0f;
DoSomething(x); //ERROR! Cannot convert 'scalar' to 'float'
}
I could just do something like this:
DoSomething(x.Value());
Where x.Value() returns the floating-point value of "x", but I would rather not. It doesn't look pretty [grin] If you have a better solution, please let me know. Thanks!
C++: auto-cast a class?
I have a wrapper for the float type, called Scalar, which I'm using while building my physics engine. Is there any way that I could automatically cast the Scalar class into a float? For example, currently, this would give an error:
Give your scalar class an "operator float":
Note that these implicit conversions are generally considered poor style - what does your Scalar class provide that a pure float does not?
class Scalar{public:operator float() const{ return value; }float value;};
Note that these implicit conversions are generally considered poor style - what does your Scalar class provide that a pure float does not?
Quote:Original post by bakery2k1
Give your scalar class an "operator float":
*** Source Snippet Removed ***
Note that these implicit conversions are generally considered poor style - what does your Scalar class provide that a pure float does not?
the ability to be changed to a double at a single point in the program,
should the need arise
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement