#include <string>
#include <iostream>
std::string(foo);
int main()
{
std::cout << foo.size() << "\n";
return 0;
}
Results in 0
, instead of an expected compile error for foo
being undefined.
How is it able to do this? What is this called?
std::string(foo); //#1
is the same as
std::string (foo); //#2
is the same as
std::string foo; //#3
The parentheses in #2
are redundant. They are needed in #1
as there is no whitespace separating std::string
and foo
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With