Hi. Code Sample Code: #include <iostream> using namespace std; class A { public: A() { throw 0; } }; int main() { try { A *pA = new A; delete pA; } catch (...) { } } Is this good code and why? Constructor throws an exception. Now will the destructor be called ? When is the memory allocated when a new is called? Is it after the constructor is executed or just when the constructor starts? What happens with memory allocated for the object itself? Who's responsible for deallocating it in such a case?
Why constructors do not have return values? What if I want to check whether the object is successfully created. We could have checked that by returning some value and finding it.
Write a simple template program where the .h files contains the class definition and .cpp files contains the class declaration.
I always understood that in C++, if I said a + b a.operator+(b) is called. Now this makes sense with the operator<< when used in the following way cout << 100; // converts to cout.operator<<(100); but then how does one explain this one cout << end; // endl(cout). In what order does C++ look for operator functions? What all functions does it search before giving up? In other words when C++ sees a+b does it look for the existence of : a.operator(b) b(a) a(b) ....??? or is the operator<< a special case?
I had the plans of putting the questions only but if you wish to post the answers quote the message and put them as a post to the thread as well. There is always an option of searching within the thread so that wont be a probs.