Marshal art with objects Author – Subhasis Nayak
Rule - 1  <ul><li>Defining class does not create object of that class. </li></ul><ul><li>It just tell compiler what type o...
Let’s define a class & create it’s object <ul><li>Defining class </li></ul><ul><li>Creating object </li></ul><ul><ul><li>c...
Rule -2  <ul><li>Member function memory allocation done at when they art defined it means before the object created ,we ca...
Array of objects <ul><li>An array having class type elements known as array of objects. </li></ul><ul><li>We can create an...
Objects as function <ul><li>We can use our objects as function argument as we do for variables. </li></ul><ul><li>There ar...
Syntax for object as arguments for function <ul><li>By value </li></ul><ul><li>By reference </li></ul><ul><li>Class math{ ...
Program
Upcoming SlideShare
Loading in...5
×

how to create object

268

Published on

passing object

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
268
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

how to create object

  1. 1. Marshal art with objects Author – Subhasis Nayak
  2. 2. Rule - 1 <ul><li>Defining class does not create object of that class. </li></ul><ul><li>It just tell compiler what type of information the object of this class type will hold. </li></ul><ul><li>You can not create object of a class before the defining the class. </li></ul><ul><li>Objects can be created like any other variable, using the class name. </li></ul>
  3. 3. Let’s define a class & create it’s object <ul><li>Defining class </li></ul><ul><li>Creating object </li></ul><ul><ul><li>class student { </li></ul></ul><ul><ul><li>int id; </li></ul></ul><ul><ul><li>char name[25]; </li></ul></ul><ul><ul><li>}; </li></ul></ul>student stu1,stu2;
  4. 4. Rule -2 <ul><li>Member function memory allocation done at when they art defined it means before the object created ,we can say when class is created. </li></ul><ul><li>No separated memory space is allocated for member function when object is created. </li></ul><ul><li>But the data members memory allocation is done when object is created. </li></ul>Why all these happened so?
  5. 5. Array of objects <ul><li>An array having class type elements known as array of objects. </li></ul><ul><li>We can create an array which each block will hold an object . </li></ul><ul><li>The objects must be of a single class. Why? </li></ul><ul><ul><li>class student { </li></ul></ul><ul><ul><li>int id; </li></ul></ul><ul><ul><li>char name[25]; </li></ul></ul><ul><ul><li>}; </li></ul></ul>student stu[6];
  6. 6. Objects as function <ul><li>We can use our objects as function argument as we do for variables. </li></ul><ul><li>There are two way of passing object as arguments: </li></ul><ul><ul><li>By value – function creates a copy of that object and used it. Here the original will not affected </li></ul></ul><ul><ul><li>By reference – here the object’s memory address passed. Hence function work with original object not with it’s copy. Original will affected. </li></ul></ul>
  7. 7. Syntax for object as arguments for function <ul><li>By value </li></ul><ul><li>By reference </li></ul><ul><li>Class math{ </li></ul><ul><li>Int x =100; </li></ul><ul><li>Void multi(math & m){ </li></ul><ul><li>m.x= m.x+100; </li></ul><ul><li>Cout<<“ ”<<m.x; </li></ul><ul><li>} </li></ul><ul><li>Void display(math m){ </li></ul><ul><li>Cout<<“ ”<<m.x; </li></ul><ul><li>} </li></ul><ul><li>}; </li></ul><ul><li>Class math{ </li></ul><ul><li>Int x =100; </li></ul><ul><li>Void multi(math m){ </li></ul><ul><li>m.x= m.x+100; </li></ul><ul><li>Cout<<“ ”<<m.x; </li></ul><ul><li>} </li></ul><ul><li>Void display(math m){ </li></ul><ul><li>Cout<<“ ”<<m.x; </li></ul><ul><li>} </li></ul><ul><li>}; </li></ul>Class math{ Int x =100; Void multi(math m){ t.x= x+100; Cout<<“ ”<<m.x; } Void display(math m){ Cout<<“ ”<<m.x; } };
  8. 8. Program

×