Marshal art with objects Author – Subhasis Nayak
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.
Let’s define a class & create it’s object Defining class Creating object class student { int id; char name[25]; }; student stu1,stu2;
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?
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];
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.
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<<“\n”<<m.x; } Void display(math m){ Cout<<“\n”<<m.x; } }; Class math{ Int x =100; Void multi(math m){ m.x= m.x+100; Cout<<“\n”<<m.x; } Void display(math m){ Cout<<“\n”<<m.x; } }; Class math{ Int x =100; Void multi(math m){ t.x= x+100; Cout<<“\n”<<m.x; } Void display(math m){ Cout<<“\n”<<m.x; } };
Program

how to create object

  • 1.
    Marshal art withobjects 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 aclass & 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 objectsAn 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 functionWe 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 objectas arguments for function By value By reference Class math{ Int x =100; Void multi(math & m){ m.x= m.x+100; Cout<<“\n”<<m.x; } Void display(math m){ Cout<<“\n”<<m.x; } }; Class math{ Int x =100; Void multi(math m){ m.x= m.x+100; Cout<<“\n”<<m.x; } Void display(math m){ Cout<<“\n”<<m.x; } }; Class math{ Int x =100; Void multi(math m){ t.x= x+100; Cout<<“\n”<<m.x; } Void display(math m){ Cout<<“\n”<<m.x; } };
  • 8.