I'm quite new to C++ but I find this behaviour of auto
weird:
class A{};
int main() {
A a;
auto x = -(sizeof(a));
cout << x << endl;
return 0;
}
Variable x is unsigned
in this case although I used the unary minus operator at the initialiation of the variable. How come that only the return type of sizeof
(std::size_t
) is considered but not the fact that the stored number will be negative because of the used operator?
I'm aware of size_t
being an unsigned int.
I've tried this with GCC 8.1.0 and C++17.