I was using yaml-cpp, a yaml parsing library, and I was turning crazy because my yaml document was not being parsed entirely. Turns out it’s because a constructor should have been given a reference, and not an object.
incorrect code :
ifstr;
YAML::Parser parser(ifstream("items9.yml"));
correct code :
ifstream ifstr("items9.yml");
YAML::Parser parser(ifstr);
The person told me it should not have compiled, I’m using visual C++ 10. Is this normal behaviour and should I be aware of it, or is the library wrongly designed or visual C++ wrongly accepting the code ?
This is a known issue in VS, that (unlike the standard) allows binding of non-const references to rvalues. The same can be tested with this code: