Xref: news-dnh.mv.net comp.os.msdos.djgpp:1207 Path: news-dnh.mv.net!mv!news.sprintlink.net!howland.reston.ans.net!news.starnet.net!wupost!waikato!comp.vuw.ac.nz!mu.sans.vuw.ac.nz!empty From: empty AT sans DOT vuw DOT ac DOT nz (Malcolm Taylor) Newsgroups: comp.os.msdos.djgpp Subject: Re: class and subclass funny with operator= Date: 27 Jul 1995 02:28:48 GMT Organization: SANS, Student Access Network System Lines: 17 References: Nntp-Posting-Host: mu.sans.vuw.ac.nz To: djgpp AT sun DOT soe DOT clarkson DOT edu Dj-Gateway: from newsgroup comp.os.msdos.djgpp A.Appleyard (A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk) wrote: : This test program:- : class ground{public: double x,y; : operator= (ground&g){x =g.x; y =g.y;}; : operator+=(ground&g){x+=g.x; y+=g.y;};}; : class air : public ground {public: double z;}; : main(){ground G; air A; double n; : n=A.x; n=A.y; n=A.z; : A=A; : A=G; You cannot do this. The class air can be automatically converted to a class ground, but not the other way around. There is no operator for initialising class air with class ground. C++ automatically creates the operator= for the class, and this is where it finds the error. Basically a class can de 'demoted' but not 'promoted' if you get the idea. Malcolm