|
-
April 17th, 2002, 01:21 AM
#1
dynamic cast basics
class Pet{
public:
virtual void eat(){cout<<"Pet eating"<<endl;}
};
class Dog ublic Pet{
public:
void eat(){cout<<"Dog eating"<<endl;}
virtual void sleep(){cout<<"Dog sleeping"<<endl;}
};
int main()
{
Pet* qq=new Pet;
//Dog* DD=(Dog*)qq;[1]
Dog* DD=dynamic_cast<Dog*>(qq);[2]
DD->eat();[3]
}
In the above the compilations for both static cast and dynamic cast go through.But while static cast executes [3] successfully,dynamic casting causes segmentation fault at [3].How do we explain this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|