Oops Assignment
Oops Assignment
CAas Ba
public :
vigtUCl Basec)
void Shpwl )
BaSe pt;
Derived d;
pt=&d;
ptr show ():
vintua
This pruogram wll QONON because
It troies to cou a viotuol constovcto
vintua destouto
we can not dolet a dooived Class cbjt Using a
bose CAas poiter that has a non-votual destrvctoo.
To deLOk the deoiied Cass bbjeck Using the base
base,n Desthvctiny
deoivedt Destning
lenvdDconstoutiny
constutiny
bge p-
bpto delet
v¹d deri bptr= b
d); new demved= d* de
(vod ) Mun nt
denved; Detovcling Covt
e<
d)
doived
; eonstruting t Covt
publiC:
pubiicb dUass
baseDestrutiny <<U Ut
b)vintuau
base";eonstauctingr tl( CoUt
ho b)
public:
lass
b
namocpaue
stdj Using
<iostenmy include
ri viotual contain
a must Cins bage the poite
3) Emplain chjeck siicing
tohen ademive dCaaiS objet is Signmed to,a bayo
in ctt) tho deaived ClasS objects entoa
CAass objeck
the bate
Qttebvtes ase sicod off to gnerto fomed abip.
this whol e paoe1s 's
Class objp t and
eiicig
’ The base claS obect Can' aeee33 Only the base
’ This aUso
implies he repartion 0f bage CLas nembegs
Foom doved Cos mem bers.
’ 1nert:derivedUos obet can be signed to a basp
lass obect but the other wey S`not possible. To
tackie this siing obem we can Use adynamic
pointer
pubtic :
int i
Uas deoved public base.
pUbtjc:
intK.
int mointy
deoived d j
b= dj
4) Erpiain krormous ohjet.
Ans ’Ah Ob10c4 is an in an instantR of a uas
’ uss has n0 memgy tulocatod it is JUst ike ablveint,
but when tsmst n objeet is (aeded memoy s
Culoc otead just iKe the eal - wotd instone Of tha
blvepaint
’ An objeet that does not have a mOfarente vaocbte is
nonymoUS bbjpt These aMe the type
0f objets Cocated For, jnstane use oniy
pooperties
’we n coeatO in objeet wthout aname sUch tpes
Of nameless objeet are caUied anonymous objet
’ The pojmcnyy puapose op the noymous bbjek is Just
Fos. înston t use
’ Hn AnongmouS Dbject Can be passed an aogument
to a unti on:
’ These aoe Sed to duee memony conSUmption
eloss nanelpaometoas );
inuvde <iostreany
vsing namespaLe std
int 0yb)
pubtic;
int mein()
int X}
publ ie :
viatval void Funt) -0;
int get x(){ netvm X;
int y
pUblic :
voíd FunO S cout <<.Fno cued ?
1) Dajvedd
dFunC),
ty
int numemtor lo;
int derominctor 0}
iF (denominator =0)
add (lo, 2) ;
add (s.3, 6"2)3
Yp - SUm =12