Possible Duplicate:
What’s the motivation behind having copy and direct initialization behave differently?
And by copy initialization, I mean like so:
struct MyStruct
{
MyStruct(int) {}
MyStruct(const MyStruct&) {}
};
MyStruct s = 5; // needs *both* the int and copy constructor
Despite programming in C++ for years, I never realized the above code required the copy constructor (thanks to jogojapan). The temporary had always been elided, and as such I never even knew it even existed (at least on a superficial level, despite it being optimized away) until it was pointed out to me.
After a decent amount of googling, I get the idea of how it works. My question is why is it the way it is?
Why didn't the standard make it so that the above example doesn't need the copy constructor? Is there some specific case/example that shows that requiring the copy constructor in this type of initialization is important?
Without a decent explanation of why things are they way they are, I just see this as an annoying artifact, but I'd rather not be ignorant if there's something important that I'm missing.