Function Call by Passing Object and Returning Object


Function Call by Passing Object and Returning Object



Lets take previous lecture example of Complex Number:



Here in above example , we want to add two complex number but we can't add directly c1+c2 as seen in above highlighted portion because compiler does not know it mean because it is non-primitive
data type define by user .



Now, How to add lets see:



object by c, class and object


We take add function and define within the class because only member function can access a,b of 
private member (according to property of  class which study in previous lecture of class). Now 
we call add() function by c1(caller object) , c2(as member function) pass as argument and the 
add() function was return assign in c3 as we seen in above..

Now , How to define add() lets see:

Return type of add() is assign in c3 which is complex type(as we seen in above example) therefore at  the time of defining add() is complex type and we pass 'complex c' as an argument, we take another
complex type object 'temp'. now we want to add c1.a+c2.a and c1.b+c2.b but we can't add directly 
as it's initialize in main () function as we learn in previous lecture of c language therefore we add as
'a+c.a' because we know that caller object(c1) is directly access it's member function so we can write directly 'a' which equal to c1.a and c2 pass as argument and receive by 'c' in add() therefore we can write 'c.a' equal to c2.a ,similarly, we can write' b+c.b'..


If this article is helpful to you please like share......

Comments

Popular posts from this blog

Notepad, Wordpad and Paint

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN