Your SlideShare is downloading. ×
how to create object
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

how to create object

253
views

Published on

passing object

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
253
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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