Re: pre, post increment standard behaviour, and friend function declaration

From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 01/26/04


Date: Mon, 26 Jan 2004 15:12:10 +0100

eddiew_AUS wrote:

> while playing around to check <blah> for my personal project,

What is "<blah>"?

> I discovered an anomaly with my code, compiled using (cringe) visual
> studio ver 6:
>
>
> #include<iostream>
>
> using namespace std;
>
> int main( void )
> {
> int k = 3;
> cout << k;
> cout << " " << k++ << " " << k << " " << ++k << " ";
> cout << k << "\n";
> }
>
> produces the expected output of:
> 3 4 4 4 5

I don't see why you would expect that.

>
> while
>
> #include<iostream>
>
> using namespace std;
>
> int main( void )
> {
> int k = 3;
> cout << k;
> cout << " " << k++ << " " << k << " " << ++k << " " << k << "\n";
> }
>
> produced the output of
> 3 4 4 4 3
>
> Q: Is this another example of non-standard microsoft compilers, or a
> result of the chained function calls?

It's the result of changing k's value multiple times without a sequence
point in between. The behaviour of that code is undefined.

> And another question:
> Q: Is it possible to declare the constructor of class B as a friend
> function to class A, and if so what is the syntax?

I don't think so. Constructors don't have a name.



Relevant Pages

  • what mistake I made in this head file?
    ... using namespace std; ... void compress;// throw; ... Xstr* storage_; //an array of array to store the data ... int length_; //length for each line ...
    (comp.lang.cpp)
  • Re: c interview
    ... Kenneth Brody said: ... What is the expected output of this program? ... void main ... int i = 10; ...
    (comp.lang.c)
  • Friend function problem
    ... using namespace std; ... Time::Time(int h, int m) ... void Time::AddMin ... const Time & t) ...
    (alt.comp.lang.learn.c-cpp)
  • Friend function problem
    ... using namespace std; ... Time::Time(int h, int m) ... void Time::AddMin ... const Time & t) ...
    (comp.lang.cpp)
  • Re: c interview
    ... Kenneth Brody said: ... What is the expected output of this program? ... void main ... int i = 10; ...
    (comp.lang.c)