- Bjarne Stroustrup
- Andrew Koenig - Accelerated C++
- Scott Meyers - Effective C++
- Herb Sutter Exceptional C++: 47 Engineering Puzzles http://www.gotw.ca/publications
- Andrei Alexandrescu - Modern C++ Design http://erdani.com/publications/
- Stanely Lippman -Inside the C++ Object model , C++ Primer
This blog is created to improve CPP and OOPS concept . It include OOPS concept , CPP FAQ , CPP Interview questions and many helpful material to improve CPP
Friday, April 30, 2010
Six important People of C++
Monday, April 26, 2010
Unhandeled Exceptions in C++ terminate
If a Exception is not handled With proper catch Block of same type or catch(...) is also not there terminate run-time function is called Which calls abort( ) internally .
To Avoid this we can provide our own Termination Handler function like:
OUTPUT :
terminate called after throwing an instance of 'char const*'
Aborted
OUTPUT:
Second Handler was called by terminate
To Avoid this we can provide our own Termination Handler function like:
terminate_handler set_terminate( term_function );
This can be done any where in the code . BEFORE EXCEPTION IS THROWN.
Also only one Function can be registered for as Handler
_uncaught_handler
Multiple calls of set_terminate() overwrites previous value.
OUTPUT :
terminate called after throwing an instance of 'char const*'
Aborted
Note : set_terminate is after exception is thrown.
OUTPUT:
Second Handler was called by terminate
Note :first handler is overwritten
Labels:
Exception Handling
If we throw Derived object will it catch by base or derived ? see code and Answer
Output :
base cought
NEXT Question comes in Mind is :
What if inheritance is of PRIVATE or PROTECTED
Ans: in that case object will be cought at Derived catch block only.Remember : Only Public inheritance is " IS-A "relation ., can be treated as BASE TYPE
Labels:
Exception Handling,
FAQ
Friday, April 23, 2010
Virtual Function with default Arguments
Can Virtual Functin have default Arguments?
Yes they can bu tthere is a catch here
Remember virtual functions are dynamically bound, but default parameters are statically bound .
Thing is for Runtime efficiency default parameter are not dynamically bounded .
OUTPUT:
der default 4 Passed 5
base default 4 Passed 15
Yes they can bu tthere is a catch here
Remember virtual functions are dynamically bound, but default parameters are statically bound .
Thing is for Runtime efficiency default parameter are not dynamically bounded .
OUTPUT:
der default 4 Passed 5
base default 4 Passed 15
Labels:
Default Argument,
Virtual
Friday, April 9, 2010
Some CPP certifications
1)Brain Bench, Inc. USA, C++(expert level),
2)Professional Aptitude Council, Inc. California,
C++(advanced):
2)Professional Aptitude Council, Inc. California,
C++(advanced):
Thursday, April 8, 2010
Inline Virtual Function
Inline doesn't go with Virtual . Generally compiler ignores inline directive for virtual function.
Inline has to be done at compile time but Virtual says wait until Run time At compile time compiler doesn't know which function to insert .
Point :Virtual function can be inlined if they are called by OBJ (not by pointer ) But we hardly use virtual function without Pointer
Inline has to be done at compile time but Virtual says wait until Run time At compile time compiler doesn't know which function to insert .
Point :Virtual function can be inlined if they are called by OBJ (not by pointer ) But we hardly use virtual function without Pointer
Labels:
Inline
Some Random C++ question Which I dont want to forget
Q Global object how are the created when?
OUTPUT :
Q ) Qualifiers availabel in C++ ?
Ans : I always forget mutable , 3 qualifiers are there const ,volatile and mutable .
What is Mutable .
Ans : It specifies that particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.
OUTPUT :
base CTOR
In main
base DTOR
------------------------------------------------------------------------Q ) Qualifiers availabel in C++ ?
Ans : I always forget mutable , 3 qualifiers are there const ,volatile and mutable .
What is Mutable .
Ans : It specifies that particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.
struct data
{
char name[80] ;
mutable int age ;
}
const data person = { "Amit", 24 }; // Initialisation
strcpy ( person .name, "Sharma"); // compiler error
person.salaray = 2000 ; // Allowed since it is mutable
---------------------------------------------------------------------
Q) What problem does the namespace feature solve ?
http://www.glenmccl.com/ns_comp.htm
person.salaray = 2000 ; // Allowed since it is mutable
---------------------------------------------------------------------
Q) What problem does the namespace feature solve ?
http://www.glenmccl.com/ns_comp.htm
Labels:
FAQ
Will it core ??? if yes where
My First Answer was yes De-Referencing NULL pointer will core at line 15
This is wrong function is binded to class not an object compiler just checks the TYPE of pointer and calls Func1 Successfully
It cores at line 16 where in function s=0; is doneThing is as long as no instance attribute is used in the func(), and the method is not virtual , NULL pointer need not to be dereferenced.
Labels:
Core
Tuesday, April 6, 2010
Virtual Inheritance
Well we all know why it is Required To resolve Diamond Problem
What if i have a code like this where class Bsse has no function and derived twice in Diamond way
Output: in Base In Der1 in Base Der 2 Most Derived
in Base
In Der1
Der 2
Most Derived
Accessing Base_a 0
What if i have a code like this where class Bsse has no function and derived twice in Diamond way
Output: in Base In Der1 in Base Der 2 Most Derived
Point is until we access any thing common in base class Explicitly there is NO issue
Lets see Accessing any variable from base :
Output : Compilation fails
virtual.cpp: In function `int main()':
virtual.cpp:31: error: request for member `Base_a' is ambiguous
virtual.cpp:6: error: candidates are: int Base::Base_a
virtual.cpp:6: error: int Base::Base_a
To solve we need Virtual inheritance .
Output : See the Constructor Sequence in Base
In Der1
Der 2
Most Derived
Accessing Base_a 0
Labels:
Virtual
Monday, April 5, 2010
Protected Constructor ??
these are used to make abstract class .
Class who has Protected Constructor Can 't be instantiated But available to inherit
Class who has Protected Constructor Can 't be instantiated But available to inherit
Friday, April 2, 2010
Subscribe to:
Posts (Atom)