The second function ran before the first ...


cout<<st1.countTokens()<<' '<<st1.nextToken()<<endl;

When I run this line is primarily performs the second function [nextToken()] then it is running the first function [countTokens()] then prints the return of the first and then the return of the second.

Why the first function does not start before the second?
The order in which arguments of a function calculated is undefined in C++. The expression can be written the following way

operator <<( operator <<( cout, st1.countTokens() ), st1.nextToken() );

So at first st1.nextToken() can be executed or operator <<( cout, st1.countTokens() ) is executed as arguments of external function operator <<.
Your compiler executes the right operand st1.nextToken() first.
Last edited on
Topic archived. No new replies allowed.