I need to eliminate gcc -Wconversion warnings. For example
typedef unsigned short uint16_t;
uint16_t a = 1;
uint16_t b = 2;
b += a;
gi
You could build your own abstraction to overload the +=
operator, something like
template
class myVar {
public:
myVar(T var) : val{var} {}
myVar& operator+=(const myVar& t) {
this->val = static_cast(this->val + t.val);
return *this;
}
T val;
};
int main()
{
typedef unsigned short uint16_t;
myVar c{3};
myVar d{4};
c += d;
}
It still uses a static_cast
, but you only need to use it once and then reuse it. And you don't need it in your main
.
IMHO it just adds overhead, but opinions may vary...