Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Some mind teasers (http://www.go4expert.com/forums/some-mind-teasers-t1935/)

shabbir 18Nov2006 18:34

Some mind teasers
 
I will put some mind teasers of C++ in this thread and if you have just go on adding them.

shabbir 18Nov2006 18:34

Re: Some mind teasers
 
We have

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

What is the difference?

shabbir 18Nov2006 18:38

Re: Some mind teasers
 
Are there any reasons one should avoid using static variables in abstract base classes?

shabbir 18Nov2006 18:45

Re: Some mind teasers
 
How will you call a C++ function from C and Vice Versa?

shabbir 18Nov2006 18:52

Re: Some mind teasers
 
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?

shabbir 18Nov2006 18:55

Re: Some mind teasers
 
Is it possible to catch an assertion error?

assert (false);
catch (...) {}

shabbir 18Nov2006 18:56

Re: Some mind teasers
 
Is it possible to implement a Singleton without using static variables or global variables.

shabbir 18Nov2006 18:59

Re: Some mind teasers
 
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.

shabbir 18Nov2006 19:07

Re: Some mind teasers
 
Write a simple template program where the .h files contains the class definition and .cpp files contains the class declaration.

shabbir 18Nov2006 19:08

Re: Some mind teasers
 
List the operators that cannot be overloaded normally as well as friend functions?


All times are GMT +5.5. The time now is 15:56.