<pre> //====================== start of sample.cpp ========================== struct A {}; struct B {}; struct C {}; struct D {}; struct E {}; struct F {}; void foo(int i) try { switch(i) { case 1: throw A(); case 2: throw B(); case 4: throw D(); default: throw F(); } } catch(A&) { } catch(B&) { throw D(); } catch(D&) { throw C(); } catch(...) { throw; } int main(int argc, char* argv[]) { try { foo(argc); } catch(const A& a) {} catch(const B*) {} catch(C c) {} catch(E* e) {} catch(...) { return 5; } return 0; } //====================== end of sample.cpp ========================== </pre> При каких значении argc программа вернёт значение 5?
<pre> //====================== start of sample.cpp ========================== #include <stdexcept> void my_open1() { throw int(8); } void my_open2() try { throw std::logic_error(""); } catch(std::runtime_error& err) {} void my_open3() try { throw std::runtime_error(&guot;runtime"); } catch(const std::runtime_error* err) {} struct ERR_ {}; void my_open4() { try { throw ERR_(); } catch(...) {} } int main() { try { } catch(...) { return 5; } return 0; } //====================== end of sample.cpp ========================== </pre> Вызов каких из функций изнутри блока try в функции main() приведёт к завершению программы с результатом 5?
<pre> //====================== start of sample.cpp ========================== #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> #include <vector> struct A { virtual ~A(); }; struct B: public A {}; struct C {}; void foo1(boost::shared_ptr<A>& a); void foo2(boost::shared_ptr<A const> a); void foo3(boost::shared_ptr<B>& a); void foo4(boost::shared_ptr<const A> a, boost::shared_ptr<C> c); void foo5(std::vector< boost::shared_ptr<C> >& c); int main(int argc, char* argv[]) { boost::shared_ptr<A> b1(new A); boost::shared_ptr<B> b2(new B); boost::shared_ptr<C> b3(new C); boost::weak_ptr<A> b4(b1); std::vector<boost::shared_ptr<C>> v1; v1.push_back(b3); foo1(b1); foo2(b2); foo3(b3); foo4(b4.lock(), b3); foo5(v1); return 0; } //====================== end of sample.cpp ========================== </pre> Вызовы каких функций выполнены корректно и операции создания их параметров не содержат очевидных проблем?
<pre> //====================== start of sample.cpp ========================== #include <boost/shared_ptr.hpp> #include <boost/scoped_ptr.hpp> #include <boost/weak_ptr.hpp> #include <vector> struct A { virtual ~A(); }; struct B: public A {}; struct C {}; void foo1(boost::scoped_ptr<A> a); void foo2(boost::scoped_ptr<B>& a); void foo3(boost::shared_ptr<C> a); void foo4(boost::scoped_ptr<A>* a); void foo5(std::vector< boost::scoped_ptr<C> >& c); int main(int argc, char* argv[]) { boost::scoped_ptr<A> b1(new A); boost::scoped_ptr<B> b2(new B); boost::scoped_ptr<C> b3(new C); boost::scoped_ptr<A> b4; std::vector< boost::scoped_ptr<C> > v1; v1.push_back(b3); foo1(b1); foo2(b2); foo3(b3.lock()); foo4(&b4); foo5(v1); return 0; } //====================== end of sample.cpp ========================== </pre> В каких из функциях умный указатель boost::scoped_ptr используется правильно?
<pre> //====================== start of sample.cpp ========================== #include <boost/shared_ptr.hpp> #include <boost/scoped_ptr.hpp> #include <boost/weak_ptr.hpp> #include <vector> struct A { virtual ~A(); }; struct B: public A {}; struct C {}; void foo1(boost::shared_ptr<A> a); void foo2(boost::weak_ptr<B>& a); void foo3(boost::shared_ptr<C> a); void foo4(boost::scoped_ptr<A>& a); void foo5(std::vector< boost::weak_ptr<C> >& c); int main(int argc, char* argv[]) { boost::shared_ptr<A> a(new A); boost::shared_ptr<B> b(new B); boost::shared_ptr<C> c(new C); boost::weak_ptr<A> b1(a); boost::weak_ptr<B> b2(b); boost::weak_ptr<C> b3(c); std::vector< boost::weak_ptr<C> > v1; v1.push_back(b3); foo1(b2.lock()); foo2(b2); try { boost::shared_ptr<C> c1(c); foo3(c1); } catch(boost::bad_weak_ptr& e) { } foo4(b2.lock()); foo5(v1); return 0; } //====================== end of sample.cpp ========================== </pre> Вызовы каких функций выполнены корректно и операции создания их параметров не содержат очевидных проблем?
<pre> //====================== start of sample.cpp ========================== struct A { A(); virtual ~A(); private: A(A&a); A& operator=(const A& a); }; struct B: public A {}; struct C {}; struct D { D(); D& operator=(const D& d); }; //====================== end of sample.cpp ========================== </pre> Какие из типов из файла sample.cpp удовлетворяют требованию CopyConstructible?
<pre> //====================== start of sample.h ========================== struct A {}; struct B; struct B *pb = 0; struct A *pa = 0; struct B b; struct A a; void foo(const struct B& in_b); //====================== end of sample.h ========================== </pre> Какие присвоения и объявления в файле sample.h валидны?
<pre> //====================== start of sample.cpp ========================== struct A {}; struct B {}; struct C {}; struct D {}; struct E {}; struct F {}; int main() { try { foo(); } catch(const A& a) {} catch(static const B*) {} catch(C c) {} catch(volatile D* d) {} catch(virtual E* e) {} catch(F*&) {} catch(...) { return 5; } return 0; } //====================== end of sample.cpp ========================== </pre> Обработчики исключений какого типа записаны неправильно?
<pre>//====================== start of sample.cpp ========================== class Input { public: Input(); ~Input(); }; class USBInput: public Input { public: USBInput(); virtual ~USBInput(); }; class Device { public: Device(); ~Device(); }; class USBDevice: virtual public Device { public: USBDevice(); virtual ~USBDevice(); }; class ManualUserDev: public virtual USBInput { public: ManualUserDev(); virtual ~ManualUserDev(); }; class Key { public: Key(); ~Key(); }; class Keyboard: public Input, public Key { public: Keyboard(); ~Keyboard(); };//====================== end of sample.cpp ========================== </pre> Для которых из классов в файле sample.cpp в конструкторе может потребоваться явно вызвать конструкторы базовых классов?
<pre>//====================== start of sample.cpp ========================== class Input { public: Input(); ~Input(); virtual void f(); }; class ManualUserDev: public Input { public: ManualUserDev(); virtual ~ManualUserDev(); }; class Keyboard: public Input { public: Keyboard(); ~Keyboard(); }; int main() { Keyboard keyboard; Input& rinp = keyboard; Input* pinp = &:keyboard; ManualUserDev& rmy_mdev = dynamic_cast<ManualUserDev&>(rinp); ManualUserDev* pmy_mdev = dynamic_cast<ManualUserDev*>(pinp); Keyboard& rmy_keyboard = dynamic_cast<Keyboard&>(rinp); Keyboard* pmy_keyboard = dynamic_cast<Keyboard*>(pinp); return 0; }//====================== end of sample.cpp ========================== </pre> При инициализации какой переменной в файле sample.cpp будет брошено исключение?