Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Base {
- public: virtual ~Base() { }
- };
- class Derived : public Base {
- public: int field;
- };
- void test(Base *ptr) {
- Derived *d = dynamic_cast<Derived *>(ptr);
- if (d) {
- std::cout << "field: " << d->field << std::endl;
- } else {
- std::cout << "Not a Derived object" << std::endl;
- }
- }
- int main() {
- Base b;
- Derived d;
- test(&b);
- test(&d);
- }
- -----------------------------------------------------------
- $ g++ -fno-rtti test.cpp -o test
- test.cpp: In function ‘void test(Base*)’:
- test.cpp:12:42: error: ‘dynamic_cast’ not permitted with -fno-rtti
- Derived *d = dynamic_cast<Derived *>(ptr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement