S
Steven T. Hatton
The result shown below doesn't surprise me now. But it did several months
ago when I followed some bad advice and tried to check if I had a live
object at the address referenced by a pointer. Can I assume the result is
consistente with the Standard?
Tue May 10 21:24:24:> cat foo.cc
#include <iostream>
struct Foo{virtual ~Foo(){} };
struct Bar{virtual ~Bar(){} };
int main(){
Foo* foo = new Foo;
Bar* bar = new Bar;
std::cout << "dynamic_cast<Foo*>(foo)"
<< dynamic_cast<Foo*>(foo)
<< std::endl;
delete foo;
std::cout << "dynamic_cast<Foo*>(foo)"
<< dynamic_cast<Foo*>(foo)
<< std::endl;
std::cout << "dynamic_cast<Foo*>(bar)"
<< dynamic_cast<Foo*>(bar)
<< std::endl;
}
Tue May 10 21:25:45:> ./foo
dynamic_cast<Foo*>(foo)0x804a008
dynamic_cast<Foo*>(foo)0x804a008
dynamic_cast<Foo*>(bar)0
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
ago when I followed some bad advice and tried to check if I had a live
object at the address referenced by a pointer. Can I assume the result is
consistente with the Standard?
Tue May 10 21:24:24:> cat foo.cc
#include <iostream>
struct Foo{virtual ~Foo(){} };
struct Bar{virtual ~Bar(){} };
int main(){
Foo* foo = new Foo;
Bar* bar = new Bar;
std::cout << "dynamic_cast<Foo*>(foo)"
<< dynamic_cast<Foo*>(foo)
<< std::endl;
delete foo;
std::cout << "dynamic_cast<Foo*>(foo)"
<< dynamic_cast<Foo*>(foo)
<< std::endl;
std::cout << "dynamic_cast<Foo*>(bar)"
<< dynamic_cast<Foo*>(bar)
<< std::endl;
}
Tue May 10 21:25:45:> ./foo
dynamic_cast<Foo*>(foo)0x804a008
dynamic_cast<Foo*>(foo)0x804a008
dynamic_cast<Foo*>(bar)0
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell