Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <typeinfo>
- using namespace std;
- class Base {
- public:
- void f() {
- std::cout << 2 << " ";
- }
- virtual void g() {
- std::cout << 7 << " ";
- }
- };
- class Derived:public Base {
- public:
- void f() {
- std::cout << 1 << " ";
- }
- void g() {
- std::cout << 3 << " ";
- }
- virtual void h() {
- std::cout << 4 << " ";
- }
- };
- class Young:public Derived {
- public:
- void h() {
- std::cout << 9 << " ";
- }
- };
- int main() {
- Base *a;
- Derived b;
- Base *c = new Base;
- Base *d = new Derived;
- Derived *e = new Derived;
- Base *u = new Young;
- cout << (static_cast<Derived*>(c)==nullptr) << " ";
- cout << (dynamic_cast<Derived*>(c)==nullptr) << " ";
- cout << (static_cast<Derived*>(d)==nullptr) << " ";
- cout << (dynamic_cast<Derived*>(d)==nullptr) << " ";
- cout << (static_cast<Derived*>(u)==nullptr) << " ";
- cout << (dynamic_cast<Derived*>(u)==nullptr) << " " << endl;
- cout << (typeid(*u)==typeid(Base)) << " ";
- cout << (typeid(*u)==typeid(Derived)) << " ";
- cout << (typeid(*u)==typeid(Young)) << " " << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement