Some mind teasers

shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I will put some mind teasers of C++ in this thread and if you have just go on adding them.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
We have

const A& operator=(const A& obSrc)
and
A& operator=(const A& obSrc)

What is the difference?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Are there any reasons one should avoid using static variables in abstract base classes?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
How will you call a C++ function from C and Vice Versa?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Is it possible to catch an assertion error?

assert (false);
catch (...) {}
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Is it possible to implement a Singleton without using static variables or global variables.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Write a simple template program where the .h files contains the class definition and .cpp files contains the class declaration.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
List the operators that cannot be overloaded normally as well as friend functions?