I wrote the following code:
#include <iostream>
using namespace std;
class A
{
int i;
public:
A(int ii = 0) : i(ii) {}
A(const A& a)
{
i = a.i + 1;
cout << i << endl;
}
};
A f(A a)
{
A a2 = a;
return a2;
}
int main()
{
A a1;
A a2;
a2 = f(a1);
return 0;
}
compiling this with g++
(no additional flags, same result if I add the -O0 flag) and running results:
1
2
compiling in VS2010 pro resulted:
1
2
3
what's going on here?