[ Matter here is just notes. No authenticity can be assured]How Exception can be handled at constructor ?- When exception happened in constructor, destructor will not called and memory leak would happened.
-
"function-try-block".is the mechanism, which can use to handle the exceptions at constructor.
- Or separate initialization functions can be used, instead of constructor.
Few Links :
- http://www.cs.technion.ac.il/~imaman/programs/throwingctor.html
- http://www.open-std.org/jtc1/sc22/open/n2356/except.html#except
- http://www.parashift.com/c++-faq-lite/exceptions.html
Notes :
- - A pointer declared inside try block will not be accesible in catch block.
How to make a procedure/function invisible to outside a library ?- Declare the procedure or function as static. So the function can be accessible inside the file/library only.
Eg. static int get_user_conf()
How is the static variable and static functions in C++- Static variables are part of class, not with object
- Static variable should be intialised after class definition.
eg. int base::counter=10;
- A non static function also can access static variables.
Eg. void increment_counter()
{
base::counter++; // base:: qualifier required.
}
- A static class can access only static variables, part of the class.
What is placement new ? - Placement new is a mechanism in c++ which allows user to allocate memory from pre-allocated buffer.
- Standard C++ supports placement new operator, which constructs an object on a pre-allocated buffer (memory, which is already alocated). This is useful when building a memory pool, a garbage collector or simply when performance and exception safety are paramount (there's no danger of allocation failure since the memory has already been allocated, and constructing an object on a pre-allocated buffer takes less time):
Example :
void placement() {
char *buf = new char[1000]; //pre-allocated buffer
string *p = new (buf) string("hi"); //placement new
string *q = new string("hi"); //ordinary heap allocation
}