delete() confusion!

I

Ian McBride

Plus or minus a few typos, in the pseudo-program below, which delete
operator gets called, Base1's delete or the default delete?

Thanks for any help..

--
class Base1
{
public:
void operator delete(void *);
void * operator new(int size);
};

class Base2
{
public:
virtual ~Base2();

Dispose()
{
delete this;
}
};

class Derive : virtual public Base1, virtual public Base2
{
int MemberVar;
};

main()
{
Base2 * p = new Derive;
p->Dispose();
}
--
 
B

Buster Copley

Ian said:
Plus or minus a few typos, in the pseudo-program below, which delete
operator gets called, Base1's delete or the default delete?

Neither, unless you have a suitable pseudo-compiler. Fix the "typos" and
add dummy function definitions which output suitable messages. That will
tell you what your real compiler thinks the answer should be.
Thanks for any help..

--
class Base1
{
public:
void operator delete(void *);
void * operator new(int size);
};

class Base2
{
public:
virtual ~Base2();

Dispose()
{
delete this;
}
};

class Derive : virtual public Base1, virtual public Base2
{
int MemberVar;
};

main()
{
Base2 * p = new Derive;
p->Dispose();
}
--

Good luck,
Buster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,237
Latest member
AvivMNS

Latest Threads

Top