От: | crable | ||
Дата: | 25.10.05 07:57 | ||
Оценка: | 2 (1) |
А>class A
А>{
А>public:
А> int a;
А> A():a(0){};
А> A& operator=(const A copy)
А> {
А> a=copy.a;
А> return *this;
А> }
А>};
А>class B:public A
А>{
А>public:
А> int b;
А> B():b(0)
А> {}
А> operator A()
А> {
А> A A1;
А> A1.a=b-1;
А> return A1;
А> }
А> B& operator=(const B copy)
А> {
А> b=copy.b;
А> a=copy.a;
А> return *this;
А> }
А>};
А>class C:public B
А>{
А>public :
А> int c;
А> C():
А> c(0)
А> {
А> }
А> operator B()
А> {
А> B B1;
А> B1.b=c-1;
А> return B1;
А> }
А> C& operator=(const C copy)
А> {
А> c=copy.c;
А> b=copy.b;
А> a=copy.a;
А> return *this;
А> }
А>};
А>int main(void)
А>{
А> C c;
А> c.c=5;
А> std::cout<<((B)c).b;//Здесь хотелось бы чтобы вывелось 4
А> return 0;
А>}
А>
A conversion function is never used to convert a (possibly cv-qualified) object to the (possibly cv-qualified) same object type (or a reference to it), to a (possibly cv-qualified) base class of that type (or a reference to it), or to (possibly cv-qualified) void.