Class and Structure
Class and Structure
Difference between Class and Structure :
Lets understand with examples : write a program of complex numbers.
1- Program of Complex number with Structure
structure |
Here we know that private member of structure can't accessible from outside as we discuss in our
previous lecture of structure.if you don't saw so please go to that lecture of STRUCTURE for better understand the concept of Class.
2- Program of Complex number with Class
class |
Here we seen that without written of Private access specifier int a,b by default consider as
Private member.
Now, lets discuss some property of Class :
1- Class variables called object
Here in above example , we seen that c1 is an object or we can say that c1 is noun and set_data(3,4)
is verb mean c1 is name which perform some action like set_data(3,4). Remember in class member
function directly access by its object as we seen in above example that c1 directly access
set_data function variable i.e 3,4 when it is called.
2- How to define member function outside the class.
Here in above example we can seen that 'set_data' function is define outside the class but its consider
as member function of class because we used membership label i.e "complex:: " while defining function and we have to declare it's function inside the class i.e void set_data(int,int) as we seen
in above. Remember function define inside the class 'by default' consider as inline function
but when you define it outside the class then to make it inline function with help of inline keyword.
If this article is helpful to you then please like and share.. thank you..
Comments
Post a Comment