Skip to main content

Posts

Showing posts from November, 2014

How copy constructor is different from constructor?

A copy constructor is used to declare and initialized an object from another object. But constructor enables an object to initialize itself when it is created. It is known as automatic initialization of object. So copy constructor is different from constructor.      For Example:      #include<iostream.h>       class copy   {         int id;      public:       copy()     {   }     copy(int a);       {          id=a;      }         copy(copy & x)     {        id=x.id;       }    void display(void)     {         cout<<id;     }    }; void main()      {         copy a(300);         copy b(a);         copy c=a;         copy d(b);           cout<<"\n ID of a:  ";a.display();           cout<<"\n ID of b:  ";b.display();           cout<<"\n ID of c:  ";c.display();           cout<<"\n ID of d:  ";d;display();     return();        } Output of this program is: ID of a: 300 ID of

Basic History on C++:

Ø   It was developed by Bjarne Stroustrup at AT&T Lab in the early 1980’s. Ø   Initially, it was called “C with classes”. After 1983, it was being called as C++ (C=C+1 or C+=1) i.e. incremented version of C. Ø   C++ is superset of C. All C programs are also C++ programs but not vice versa. Ø   C++ supports Object Oriented Programming (OOP).

How containership is different than inheritance ?

               Inheritance is the mechanism of deriving properties of one class into another. While containership is mechanism in which one class contain objects of other classes as its member.                     class alpha{_ _ _ _ _ };                     class beta{_ _ _ _ _ };                      class gamma                      {                         alpha a;                         beta b;                       _ _ _ _ _ };            All objects of gamma class will contain the objects a and b, this kind of relationship is called containership or nesting.