Back
Close

Quiz 27

Anonymous
1,390 views

description:

deleting NULL pointers have no effect. deleting a pointer to a base class which points to a derived object is legal assuming the base destructor is virtual. deleting an array of objects using a base class pointer is undefined.

struct Foo
{
virtual ~Foo() {}
};
struct Bar : public Foo
{
};
int main(int argc, char** argv)
{
Foo* f = new Bar;
delete f;
f = 0;
delete f;
Foo* fa = new Bar[10];
delete [] fa;
fa = 0;
delete fa;
return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants