[an error occurred while processing this directive]
Ещё вариант +
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Kenat 13 января 2006 г. 16:51
В ответ на: RTTI + отправлено Kenat 13 января 2006 г. 16:50


class Base1
{
// In order for the RTTI mechanism to function correctly,
// a base class must be polymorphic.
virtual void f(void) { /* A virtual function makes the class polymorphic */ }
};

class Base2 { };
class Derived : public Base1, public Base2 { };

int main(void) {
try {
Derived d, *pd;
Base1 *b1 = &d;

// Perform a downcast from a Base1 to a Derived.

if ((pd = dynamic_cast(b1)) != 0) {
std::cout << "The resulting pointer is of type "
<< typeid(pd).name() << std::endl;
}
else throw Bad_cast();

// Attempt cast across the hierarchy. That is, cast from
// the first base to the most derived class and then back
// to another accessible base.
Base2 *b2;
if ((b2 = dynamic_cast(b1)) != 0) {
cout << "The resulting pointer is of type "

<< typeid(b2).name() << endl;
}
else throw Bad_cast();
}
catch (Bad_cast) {
cout << "dynamic_cast failed" << endl;
return 1;
}
catch (...) {
cout << "Exception handling error." << endl;
return 1;
}

return 0;

}


Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 
NoIX ключ Запомнить

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание

E-mail: info@telesys.ru