Bloomberg LP Interview Question
Software Engineer / DevelopersYou cannot make sure. Example:
class X
{
private:
~X () {}
};
void f ()
{
char p [1000];
X* x = new (p) X ();
}
destructor in private, but x is on stack
C++ is not a policeman. You cannot even prevent from others using you private members. Example:
#define private public
// include here someone else's code --->
class X
{
private:
void f () { cout << "f" << endl; }
};
// include here someone else's code <---
#undef private
struct Y : X
{
void g ()
{
f ();
}
};
Voila - you are using other class private function!
Make dtors private
- Anonymous August 08, 2010