Say I have a class, that wraps some mathematic operation. Lets use a toy example
class Test
{
public:
Test( float f ) : mFloat( f ), mIsInt( false ) {}
fl
You can't "overload/add" operators for basic types, but you can for your type Type
. But this shall not be operator =
but operator >>
- like in istream
s.
class Test
{
public:
float mFloat;
int mInt;
bool mIsFloat;
Test& operator >> (float& v) { if (mIsFloat) v = mFloat; return *this; }
Test& operator >> (int& v) { if (!mIsFloat) v = mInt; return *this; }
};
Then you can:
int main() {
float v = 2;
Test t = { 1.0, 2, false };
t >> v; // no effect
t.mIsFloat = true;
t >> v; // now v is changed
}
Update
I want to do something like:
updateTime = config["system.updateTime"];
Then with my proposal, you cam:
config["system.updateTime"] >> updateTime;