Some C++ TIPS

* Returning reference of a private variable of a class through public function gives the power to the accessor to change the value of that. (Voilation of Data abstraction :- But people want to violate the rules always).
p.s. Hence never return a reference of a pvt variable of a class.

Virtual Tips(Not "REAL"ly..)

* Virtual Constructor is not allowed, but you can simulate its behaviour using a virtual creator
   function.
       For eg. In base class define a virtual function which returns a new pointer of its own type. This type of function is generally termed as factory function in design pattern.
        class Base
        {
                 public:
                 //constructors, destructors, functions etc.
                 virtual Base* myFactory(){return new Base();}
        }
     Then the derived class can override this function to create a new of its own type & return it. Thus virtual constructor can be simulated.

* Definition for Pure Virtual function is allowed and it can be called (hint: via the derived class instance using scope operator as there can be no instance of class with pure virtual function). It holds good for Destructor also.

* Multiple Inherited class from the same grand parent will maintain as many copies as required. So accessing its grand parent's member should be resolved by scope operator of its parent(s). If you want to maintain only a single copy of grand parent the parent classes must be virtually derived from the grand parent (Ahaaa ...).

Static tips( Be "DYNAMIC" in understading this)

* Static variable of a class has only one instance for all its members

* Static functions can access & manipulate only static variables of that class. However if you pass an instance(object) of that class through that you can do accessing and manipulation of its non-static variables.

* Static functions can be accessed through class name followed by scope operator like any ordinary global function. No instantiation of class is necessary for this.

* Initialize the static variables of any class globally.

Exception(ally Good) tips

* "try" to "throw" an exception before "catch"ing it.

* Exception raised in the program only can be handled.

* "catch" should follow "try",otherwise you'll miss it. (Error!)

* catch all type of exception you are throwing. Else abort.

This page is what i thought will be useful & try to update it whenever i think (or learn) something useful.

Back to

This page hosted by 
Get your own Free Home Page

1