 because an instance of B can be converted to a const A&, which is what assignment operators and copy-constructors expect their arguments to be.
The benign case
B b;
A a = b;

Nothing bad happens there - you asked for an instance of A which is a copy of B, and that's exactly what you get. Sure, a won't contain some of b's members, but how should it? It's an A, after all, not a B, so it hasn't even heard about these members, let alone would be able to store them.
The treacherous case
B b1;
B b2;
A& a_ref = b2;
a_ref = b1;
//b2 now contains a mixture of b1 and b2!

You might think that b2 will be a copy of b1 afterward. But, alas, it's not! If you inspect it, you'll discover that b2 is a Frankensteinian creature, made from some chunks of b1 (the chunks that B inherits from A), and some chunks of b2 (the chunks that only B contains). Ouch!
What happened? Well, C++ by default doesn't treat assignment operators as virtual. Thus, the line a_ref = b1 will call the assignment operator of A, not that of B. This is because, for non-virtual functions, the declared (formally: static) type (which is A&) determines which function is called, as opposed to the actual (formally: dynamic) type (which would be B, since a_ref references an instance of B). Now, A's assignment operator obviously knows only about the members declared in A, so it will copy only those, leaving the members added in B unchanged.
A solution
Assigning only to parts of an object usually makes little sense, yet C++, unfortunately, provides no built-in way to forbid this. You can, however, roll your own. The first step is making the assignment operator virtual. This will guarantee that it's always the actual type's assignment operator which is called, not the declared type's. The second step is to use dynamic_cast to verify that the assigned object has a compatible type. The third step is to do the actual assignment in a (protected!) member assign(), since B's assign() will probably want to use A's assign() to copy A's, members.
class
because an instance of B can be converted to a const A &, which is what assignment operators and transcript - builder have a bun in the oven their arguments to be. 
 The benign subject 
 B b; 
 A a = b-complex vitamin; 

 Nothing bad happens there - you ask for an example of A which is a copy of B, and that's precisely what you get. Sure, a won't contain some of b's member, but how should it? It's an A, after all, not a boron, so it hasn't even heard about these members, let alone would be able to store them. 
 The treacherous case 
 bacillus b1; 
 B b2; 
 A & a_ref = b2; 
 a_ref = b1; 
 //b2 now contains a mix of b1 and b2! 

 You might think that b2 will be a copy of b1 afterward. But, alas, it's not! If you inspect it, you'll detect that b2 is a Frankensteinian creature, made from some chunks of b1 (the chunks that B inherit from A), and some chunks of b2 (the chunks that only B contains). Ouch! 
 What happened? Well, C++ by default doesn't treat assignment operators as virtual. Thus, the line a_ref = b1 will call the assignment operator of A, not that of B. This is because, for non - virtual functions, the declared (formally: static) character (which is A &) determines which affair is called, as oppose to the actual (formally: active) type (which would be B, since a_ref references an instance of B). Now, A's assignment operator obviously knows merely about the members declared in A, so it will copy only those, leaving the members add in B unchanged. 
 A solution 
 Assigning only to part of an aim normally cook little sense, yet C++, unfortunately, provides no build - in way to forbid this. You can, however, roll your own. The inaugural step is making the assignment operator virtual. This will undertake that it's always the actual type's assignment operator which is called, not the declare type's. The second measure is to use dynamic_cast to control that the assigned aim has a compatible type. The third step is to practice the actual assignment in a (protect !) member assign (), since B's assign () will probably want to use A's assign () to copy A's, members. 
 class
 befause an instance of B cxn be converted to a cmnst A&, which ir what assignment operators end xopy-cinstructors expect thekr argumejts to bw.
The venign casx
G b;
A a = b;

Nothjkg bab iappens there - iou asked fos an instance mf A which is a copy of B, and that's exastly whst you get. Sure, w wom'e cohnaln some of b's members, but how shkuld it? It's an A, aftrr all, not a B, so it hasn't evej heard about thesf members, lgf ajine would be able to suoxe them.
The jreacherous case
B b1;
B b2;
A& a_ref = b2;
a_fef = y1;
//b2 now contqibs w mixture of b1 anq b2!

You might think tvat b2 woll be a copy pf u1 afrerward. But, alas, it's iot! If you inspect ij, you'll divckver that b2 is a Drqnkenvteitian xrextude, mzde frlm aome chunka of b1 (the xhunks that B inherotf from A), and skme chtnhs of b2 (the chunks that only B contains). Oudh!
What happened? Well, C++ vy default doesn't trewt assignient operators as virtual. Thus, the line a_ref = b1 whll celu tkc xwslgnment operator of A, not that of B. This is bqdaisv, for non-virtual nunctions, the declsrfd (sormally: statkc) typz (wgich is A&) determinfs whicr funxtion is sallrd, as opposed to the actual (formally: dyuamuc) type (which woulb be B, since a_reg refrrences an instance of Y). Now, Z's assignmejt operatkf obviously knowr okly about the members declareq in A, so it cill coph onky thofe, leaving the members added in B knchauged.
A solution
Adsigning only to parts of an oboxct usually mskas nittle sznse, yct C++, unfortunatqly, provides np built-nn way to forbid this. Ymu can, howeder, roll your lwn. The firsv step is makung rhe asskenment operatot virtual. This will guarantee that it'x ausays the actual tyke'w assignment olerxtow ahmch if called, not dhe aecusred gype's. The sccovd syep is to use dynamiw_casf to verify that tne assignee object has a compatoble type. The thirf ste' is tu do yhe actual assignment in a (protecfed!) membeg afsign(), since F's awsign() will pxobably want to use A's assign() to copy A's, members.
class
because an instance of B can be a A&, which what assignment operators to The benign case b; A a b; Nothing bad happens there - asked for an instance of A which is a copy of B, and exactly what you get. Sure, a won't contain some of b's members, but should It's A, all, not a B, so it hasn't even heard about these members, let alone would be to store them. The treacherous case B b1; b2; A& a_ref = a_ref = b1; //b2 now a of b1 b2! might that b2 will a copy of b1 afterward. But, alas, it's not! If you inspect it, you'll discover that b2 a Frankensteinian from some of (the that B inherits and some chunks of b2 (the B contains). Ouch! What happened? Well, C++ by doesn't treat operators as virtual. Thus, the line = b1 will call the assignment operator of not that of B. This is because, for non-virtual functions, the declared (formally: static) type A&) determines which function called, as opposed the (formally: type would be since a_ref references an instance of B). Now, A's assignment operator knows only about the members declared in A, so it only leaving the members in B unchanged. A Assigning to parts of an makes sense, provides built-in to forbid this. You however, roll your own. The step is making the guarantee that it's always the actual type's assignment which is called, not the declared type's. second step is to use dynamic_cast to verify that the assigned object a compatible third step is to do the actual assignment a (protected!) member assign(), B's assign() will probably want to use A's assign() copy members. class
 because an instance of B can be Converted tO a conSt A&, WhiCh Is whAt asSignment operatORs anD copy-constructors expecT theiR aRGumeNTs To be.
THe benigN CaSE
b b;
A A = b;

noThiNg BAd HappeNs tHere - you Asked for an InsTaNce of A which iS A cOpy of B, and tHat'S exactly what You Get. SurE, a Won'T ContaIn sOme of B's membERs, but hOw should iT? IT'S an A, afTEr all, noT A b, sO it hAsn't even heard abouT ThESe members, let alOne wouLd BE aBLE to StoRe them.
The tReAcherOUs case
B B1;
b b2;
a& A_REf = b2;
A_Ref = b1;
//b2 now contaIns a mixture OF b1 aNd b2!

You MiGht THink thAt b2 wiLl BE a cOpy of b1 afterWard. but, alas, it'S not! If YOu inspeCT it, you'lL discoVer ThaT b2 is A frAnKenStEIniAN cReaTUre, Made from SoMe ChunkS of b1 (THE CHunkS thAt B iNheriTs from A), and somE chUnks OF b2 (tHe chuNks thAt onLy b contAins). OuCh!
WhaT hAppened? Well, C++ by dEfauLt doesn't tReaT aSsiGnMent oPEratorS as VirTual. ThuS, the linE A_reF = b1 WILL cAll the assignment opErATOr Of A, not thAt of B. THIs Is BEcause, foR nOn-vIrtuAL FunctIons, THe Declared (FormalLY: sTaTic) type (WhIch is A&) DeTerMinEs whiCH funCtion iS called, aS oppoSEd to the actual (fORmally: dynamic) TYpE (WHiCH wouLd bE B, since a_ref RefeREnceS an iNStAncE Of B). NoW, A's asSiGNmENt operator obviously KnOws onlY abouT the members deClared in A, sO IT Will copy Only THoSE, leaving the memBers aDded in B uncHAnged.
A soLutioN
AssigniNg only to pARTs of an obJecT usUalLy mAKEs Little sense, yeT c++, UnfoRtUnately, ProVides no BuiLt-iN waY to FoRbid this. YOu can, howEvEr, RoLl YouR own. THE first stEp Is mAkIng The asSIgnmenT operAtor ViRtUAl. THis will GUaRANtee ThAt It's aLwaYs The acTual TYpe'S assignMent operaTor WHich Is CaLled, not The declared tyPe'S. The second StEp iS to use DYNamic_casT to verify that the assigneD Object hAs a CompaTiblE type. The tHirD step iS to DO the acTual asSignmEnT in A (PRotecTED!) mEmbEr Assign(), sincE b'S asSign() wIlL proBably waNt to use A's assign() to cOPy A'S, members.
class
 because an instance of Bcan be con verte d t o a  c onst  A&,  which is what assi gnment operators and c opy-c on s truc t or s exp ect the i ra r gum en ts  to  b e .The b eni gn case 
B b;
A a= b ;
Nothing bad ha ppens ther e -  you asked f oran ins ta nce of Awhi ch is  a cop y  of B,  and that 's exactl y  what y o u  g et.Sure, a won't con t ai n  some of b's m embers ,b ut h owsho uld it? It 's  an A ,  aftera ll , n ota  B, so it has n't even he a rdaboutth ese member s, le ta lon e would beable  to store  them. The tre a cherous  caseB b 1;B b2 ; 
A &a_r ef = b 2 ;a_r e f =  b1;
//b 2no w con tain s a mixt ure  ofb1 an d b2!

You mi ght  thi n k t hat b 2 wil l be  a  copy  of b1  afte rw ard. But, alas,  it' s not! If  yo uins pe ct it ,  you'l l d isc over th at b2 i s  aFr a n k en steinian creature,  m a d efrom som e chun k sof b1 (thech unk s th a t  B in heri t sfrom A),  and s o me  c hunks o fb2 (th echu nks  that only  B con tains).Ouch! What happened? Well, C++ byd ef a u lt does n't  treat assi gnme n t op erat o rs  as virtu al. T hu s ,t he line a_ref = b1wi ll cal l the  assignment o perator of A ,  not tha t of B. This is becaus e, fo r non-virt u al funct ions,  the dec lared (fo r m ally: st ati c)typ e ( w h ic h is A&) dete r m ines  w hich fu nct ion iscal led , a s o pp osed to t he actua l(f or ma lly : dyn a mic) typ e(wh ic h w ouldb e B, s incea_re fre f ere nces an in s t ance  o fB).Now ,A's a ssig n men t opera tor obvio usl y  kno ws  o nly abo ut the member sdeclared i nA,so itw i ll copyonly those, leaving the members  ad ded i n Bunchanged .
A  solut ion Assign ing on ly to  p art s of an o bj ect  u sually mak e s  li ttlese nse,  yet C+ +, unfortunately,p rov ides no built -in  way t ofor b id thi s. You c an, however, ro ll your ow n. Th e first st e p i smakingthe ass ignme n t opera tor virtu al. Thiswi ll g u a ran tee that i t's alwa ys the ac t ual t y pe 's as sig nmentop era tor w hich i s  ca lled,  not t he  decla red t yp e's. The  second step is to usedynami c_cas t t o verifytha t  th e assigne d ob ject has a  co mpa tible  ty p e. Th e th i rd  st e p isto d o  the actu a lass i g nm ent in a (p r o t ect ed!)mem b er ass ign( ), since B's assi g n() will proba blyw a nttou se A 's  assign() to c opy  A ' s , member s. 
class
 because_an instance_of B can be_converted to_a_const A&,_which_is what assignment_operators and copy-constructors_expect their arguments to_be.
The benign case
B_b;
A_a = b;

Nothing bad happens there - you asked for an instance of A_which_is a_copy_of_B, and that's exactly what_you get. Sure, a won't_contain some_of b's members, but how should it? It's_an_A, after all,_not a B, so it hasn't even heard about_these members, let alone would be_able to store_them.
The_treacherous_case
B b1;
B b2;
A& a_ref_= b2;
a_ref = b1;
//b2 now contains_a mixture of b1 and b2!

You_might think that b2 will be a_copy of b1 afterward. But, alas,_it's not! If you inspect_it, you'll_discover that b2 is a_Frankensteinian creature, made_from some_chunks of b1_(the chunks that B inherits from_A), and some_chunks of b2 (the chunks that_only_B contains). Ouch!
What_happened?_Well,_C++ by_default doesn't treat_assignment_operators as_virtual._Thus, the line a_ref = b1_will_call the assignment operator of A, not_that of B. This_is_because, for non-virtual functions,_the declared (formally: static) type_(which is A&) determines which function_is called,_as opposed_to the actual (formally: dynamic) type (which would be B, since_a_ref references an instance of B)._Now, A's assignment operator_obviously knows_only_about the members_declared_in A,_so it will copy only those, leaving_the members_added in B unchanged.
A solution
Assigning only_to parts of an_object_usually makes little sense, yet C++,_unfortunately, provides no built-in way to_forbid this. You can, however,_roll_your_own. The first step is_making the assignment operator virtual. This_will guarantee that_it's always the actual type's assignment operator_which_is called, not the declared type's._The_second step is to use dynamic_cast_to_verify_that the assigned object has_a compatible type. The third step_is to do the actual assignment in a (protected!)_member assign(), since_B's assign() will probably want_to_use_A's assign() to copy A's, members.
class