O
Olumide
Hi,
I've been trying to figure out why the following bit of code does not
crash and still outputs the "Hello son" message althought its been
explicitly deleted. (BTW, I'm using the gcc 4.3.4 compiler.)
Thanks,
- Olumide
//////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
class Parent
{
public:
void speak()
{
std::cout << "Hello son" << std::endl;
}
};
class Child
{
public:
Child(Parent* _p ) : m_parent( _p )
{
}
void speakToParent()
{
std::cout << m_parent << ":: " << this << std::endl;
m_parent->speak();
}
private:
Parent* m_parent;
};
int main()
{
Parent *p = new Parent();
Child *c = new Child( p );
delete p;
c->speakToParent();
return 0;
}
I've been trying to figure out why the following bit of code does not
crash and still outputs the "Hello son" message althought its been
explicitly deleted. (BTW, I'm using the gcc 4.3.4 compiler.)
Thanks,
- Olumide
//////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
class Parent
{
public:
void speak()
{
std::cout << "Hello son" << std::endl;
}
};
class Child
{
public:
Child(Parent* _p ) : m_parent( _p )
{
}
void speakToParent()
{
std::cout << m_parent << ":: " << this << std::endl;
m_parent->speak();
}
private:
Parent* m_parent;
};
int main()
{
Parent *p = new Parent();
Child *c = new Child( p );
delete p;
c->speakToParent();
return 0;
}