I have two code snippets:
This does not compile:
std::string reverseSentence(std::string sentence) {
std::stringstream stream = sentence;
}
This does:
std::stringstream stream (sentence);
It's my understanding that T foo = expr is T foo(expr). Thus, aren't the two stringstream initializations equivalent? Why is one compiling and the other not?
The constructor of
std::basic_stringstreamtakingstd::stringis marked asexplicit, it's not considered in copy initalization likestd::stringstream stream = sentence;.std::stringstream stream (sentence);is direct initialization, which considersexplicitconstructors too.