C++ variable declaration question

Status
Not open for further replies.

Sbodd

Ars Tribunus Militum
1,847
It's been a long time since I've done some significant C++, and I just bumped into something that strikes me as weird. (We're using Visual C++ 6.)

Short form of the question: what's the difference between the two variable declarations

Code:
std::stringstream foo;
std::stringstream bar();
I thought they'd both create a local variable of the stringstream type, constructed with the default constructor, but there's something else happening.

I've got a class with a member function prototyped as:
Code:
void Store (std::ostream &Stream);
If I use the two above variable declarations....

Code:
thing->Store(foo); //compiles OK, works
thing->Store(bar); //compile error: "cannot convert parameter 1 from [blah] to [blah].  Context does not allow for disambiguation of overloaded function."
I don't understand why the two statements differ, and my Google-fu is apparently weak. Can someone explain this to me?

Thanks!
 

Sbodd

Ars Tribunus Militum
1,847
fitten":28jn8av2 said:
bar is a function that's returning a std::stringstream?

That wasn't the intent - I wanted bar to be an instance of std::stringstream created with the default constructor. Sounds like that's what's happening, though.

kenada":28jn8av2 said:
Yeah, you’re running into what’s known as the most vexing parse.

Aha. Thanks for that. That seems unfortunate, but at least now I know why it was happening.
 
Status
Not open for further replies.