Jump to content
  • Advertisement
Sign in to follow this  
thedustbustr

stringstream constructor

This topic is 4024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this code
std::stringstream info();
info << point.x << point.y << point.z << u << v;
OutputDebugString(info.str().c_str());
causes this error
error C2296: '<<' : illegal, left operand has type 'std::stringstream (__cdecl *)(void)'
error C2297: '<<' : illegal, right operand has type 'const float'
error C2228: left of '.str' must have class/struct/union
error C2228: left of '.c_str' must have class/struct/union
though this code (omit parentheses)
std::stringstream info  ;
info << point.x << point.y << point.z << u << v;
OutputDebugString(info.str().c_str());
yields no error, but im unconvinced that it is correct. shouldn't they have identical functionality anyway? whats up? x,y,z are floats

Share this post


Link to post
Share on other sites
Advertisement
std::stringstream info(); doesn't actually construct a stringstream called info. It declares a function called info that returns a stringstream and takes no parameters. It's equivalent to std::stringstream info(void);

Basically you'll have to live without the parenthesis.

Share this post


Link to post
Share on other sites
Quote:
std::stringstream info();
The compiler parses this as a function prototype and gets confused (this is why we omit the parentheses in this context, as in your second example).

Share this post


Link to post
Share on other sites
std::stringstream info();


This is declaration of a function and it doesn't do what you want it to.


class X
{
X( int y = 17 );
}


X x(y);


or

X x; // same as x(17);



are declarations of a variable.

Share this post


Link to post
Share on other sites
This line:
std::stringstream info();
Is getting parsed as a function declairation.

Edit: Too slow x 3, I must be having an off day...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!