test avec Visual C++ :
En effet, en cast normal, y´a une recopie
- include <iostream>
using namespace std;
class A
{
public:
A(){cout << "A::A()" << endl;}
~A(){cout << "A::~A()" << endl;}
A(const A&){cout << "A::A(const A&)" << endl;}
A& operator=(const A&){cout << "A& A::operator=(const A&)" << endl;return *this;}
};
class B
{
public:
B(){cout << "B::B()" << endl;}
~B(){cout << "B::~B()" << endl;}
B(const B&){cout << "B::B(const B&)" << endl;}
B& operator=(const B&){cout << "B& B::operator=(const B&)" << endl;return *this;}
B(const A&){cout << "B::B(const A&)" << endl;}
};
int main()
{
cout << "--- init" << endl;
A a;
B b;
cout << "--- test1" << endl;
b = (B)a;
cout << "--- test2" << endl;
//a = (A)b; <--- plante a la compil : manque mét
hode pour convertir, logique.
cout << "--- test3" << endl;
b = (B&)a;
cout << "--- test4" << endl;
a = (A&)b;
cout << "--- end" << endl;
return 0;
}