S
szaki
Hi,
I have tested the piece of code below on Intel ICC and GCC compilers,
both produce the same result.
--------------------
CODE:
--------------------
#include <iostream>
using namespace std;
class X
{
public:
X() {cout << "X constructor" << endl;}
};
class B
{
public:
B(const X &x) {cout << "B constructor" << endl;}
};
int main()
{
cout << "step 1" << endl;
B b1(X());
cout << "step 2" << endl;
B b2=B(X()); //works
return 0;
}
--------------
RESULT:
--------------
step 1
step 2
X constructor
B constructor
--------------
That is, in step 1 constructors are NOT CALLED! I cannot see why. Can
anybody explain it?
Thank you
Zoltan
I have tested the piece of code below on Intel ICC and GCC compilers,
both produce the same result.
--------------------
CODE:
--------------------
#include <iostream>
using namespace std;
class X
{
public:
X() {cout << "X constructor" << endl;}
};
class B
{
public:
B(const X &x) {cout << "B constructor" << endl;}
};
int main()
{
cout << "step 1" << endl;
B b1(X());
cout << "step 2" << endl;
B b2=B(X()); //works
return 0;
}
--------------
RESULT:
--------------
step 1
step 2
X constructor
B constructor
--------------
That is, in step 1 constructors are NOT CALLED! I cannot see why. Can
anybody explain it?
Thank you
Zoltan