• Advertisement
Sign in to follow this  

Order of << operator.

This topic is 2160 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

Hiya,

I've written a couple of wrapper classes for ODBC, and I'm using the << operator in a test application.


while(resultSet->fetchNext())
{
std::cout << "ID " << resultSet->getUInt32(1) << ", " << resultSet->getString(2) << "\n";
}


This is causing an ODBC error, and I believe it's because the API requires me to access columns in increasing order.. column 1, column 2, etc.

I can see that the code is actually calling the get...() methods from right to left, which is the complete opposite of what I've always assumed...

Does anyone know a way of making it call from 'left to right' instead, without splitting into multiple lines?

Many thanks for any suggestions!

Share this post


Link to post
Share on other sites
Advertisement
The order of evaluation of subexpressions within an expression is undefined. Only between sequence points can you guarantee order of evaluation (expressions before a sequence point are guaranteed to be evaluated any expression after a sequence point). That is, it is possible for getString(2) to be evaluated before getString(1), but don't mistake that for one being printed before the other one though; the order of what is passed through the stream is well defined and guaranteed.

There is no real way to guarantee the order of evaluation inside an expression. But what is the problem with splitting it in multiple lines?
[source]
while(resultSet->fetchNext())
{
unsigned int r1 = resultSet->getUInt32(1);
unsigned int r2 = resultSet->getUInt32(2);
std::cout << "ID " << r1 << ", " << r2 << "\n";
}

[/source]

Share this post


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

  • Advertisement