C++ Basic Concepts

What does a C++ compiler gets from a compiler?

  1. Default assignment operator
  2. Default copy constructor
  3. Default constructor
  4. Default destructor
  5. Size of operator
  6. Assignment Operator2

Virtual Function:
It is a special function that resolves to the most derived version of the function with the same signature.

Example:
Base *p;
Derived d;
p = &d; 
In the above example, if the virtual function is defined in derived class d then it will be called otherwise, base class function will be called. 
 
class shape {
int x;
int y;


public int findArea(int x, int y) {
   return x*y;
 }
}

class square extends shape {
   int x;
   
   public int findArea(int x) {
       return x*x;
}

class rectangle extends shape {
}

square s = new square();
int x = 10;
int y = 20;
s.findArea(x); //Its own virtual function is called. 
rectangle r = new rectangle();
r.findArea(x,y); //Base Classes virtual function will be called. 
}
What does new keyword do?
It create another instance(new object) of the class. It will allocate space in the memory(heap) for that object;
object o = new object(); 

No comments:

Post a Comment

NoSQL

This one is reviewed but I need to delete its copy from hubpages or somewhere NoSQL Data models: key-value  Aggregate model.  key or i...