База ответов ИНТУИТ

Программирование на С/С++

<<- Назад к вопросам

<pre> //====================== start of sample.cpp ========================== #include &lt;vector&gt; template &lt;class Storage, int size&gt; class Input { public: Input() : m_store(size) {} private: Storage m_store; }; int main() { Input&lt;int,5&gt; a1; Input&lt;int,6&gt; a2; Input&lt;std::vector&lt;int&gt;,10&gt; v3; Input&lt;std::vector&lt;short&gt;,10&gt; v4; Input&lt;double, 30&gt; *pMyInput = nullptr; return 0; } //====================== end of sample.cpp ========================== </pre> Сколько описаний пользовательских типов будет в скомпилированном коде из файла sample.cpp?

(Отметьте один правильный вариант ответа.)

Варианты ответа
2
3
4
5(Верный ответ)
6
Похожие вопросы
<pre> //====================== start of sample3.h ========================== #include &lt;list&gt; #include &lt;vector&gt; template&lt;class Storage&gt; class MyIter {}; template&lt;class Storage&gt; void my_input_process(Storage* in_item) {} template&lt;class Storage, int size&gt; void clear_all(Storage*); template &lt;class Storage, class Element, int size&gt; class BackupInput {}; template &lt;class Storage, class Element, int size&gt; class Input { public: Input() : m_store(size) {} friend class MyIter&lt;Storage&gt;; friend void my_input_process&lt;Storage&gt;(Storage*); friend void clear_all&lt;Storage, 100&gt;(Storage*); friend class BackupInput&lt;Storage, Element, size&gt;; private: Storage m_store; }; Input&lt;std::list&lt;short&gt;, short, 25&gt; input25; int main() { MyIter&lt;std::list&lt;short&gt;&gt; my_iter; BackupInput&lt;std::list&lt;short&gt;, short, 25&gt; backup_input; my_input_process&lt;std::vector&lt;short&gt;&gt;(nullptr); clear_all&lt;std::vector&lt;short&gt;, 25&gt;(nullptr); clear_all&lt;std::list&lt;short&gt;, 100&gt;(nullptr); return 0; } //====================== end of sample3.h ========================== </pre> Какие функции и классы в файле sample.cpp имеют доступ к всем атрибутам глобального объекта input25?
<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&amp; rinp = keyboard; Input* pinp = &amp:keyboard; ManualUserDev&amp; rmy_mdev = dynamic_cast&lt;ManualUserDev&amp;&gt;(rinp); ManualUserDev* pmy_mdev = dynamic_cast&lt;ManualUserDev*&gt;(pinp); Keyboard&amp; rmy_keyboard = dynamic_cast&lt;Keyboard&amp;&gt;(rinp); Keyboard* pmy_keyboard = dynamic_cast&lt;Keyboard*&gt;(pinp); return 0; }//====================== end of sample.cpp ========================== </pre> При инициализации какой переменной в файле sample.cpp будет брошено исключение?
<pre>//====================== start of sample.cpp ========================== class Input { public: Input(); ~Input(); }; class USBDev { public: ~USBDev(); }; class USBInput: public Input { USBDev m_dev; public: USBInput(): Input() {} ~USBInput(); }; class Device { public: Device(); ~Device(); }; class ManualUserDev: public Device { public: ManualUserDev() : Device() {} ~ManualUserDev(); }; class Key { public: ~Key(); }; class Keyboard: public USBInput, public ManualUserDev { Key* key; public: Keyboard(): ManualUserDev(), Input() {key = new Key();} ~Keyboard() { delete key; } };//====================== end of sample.cpp ========================== </pre> В каком порядке вызываются деструкторы при удалении объекта Keyboard из файла sample.cpp?
<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(); }; class USBInput: public Input { public: USBInput(): Input() {} }; class Device { public: Device(); }; class ManualUserDev: public Device { public: ManualUserDev() : Device() {} }; class Keyboard: public USBInput, public ManualUserDev { public: Keyboard(): ManualUserDev(), USBInput() {} };//====================== end of sample.cpp ========================== </pre> Тело конструктора какого класса будет исполнено последним перед вызовом тела конструктора Keyboard при создании класса типа Keyboard?
<pre>//====================== start of sample.cpp ========================== class Input { public: Input(); }; class Output { public: Output(); }; class USBInput { }; class USBOutput { }; class SimpleComputer { long m_memory; const char* m_processor; Input m_input; Output m_output; public: long GetPerformance(); void Start(); void Reset(); }; class PersonalComputer: public SimpleComputer { USBInput m_input; UserOutput m_output; }; class LaptopComputer: public PersonalComputer { const char* m_processor; public: void Start(); void Reset(); };//====================== end of sample.cpp ========================== </pre> Какие атрибуты и методы базового класса SimpleComputer в файле sample.cpp остались не перекрыты в унаследованном классе LaptopComputer?
<pre> //====================== start of sample.cpp ========================== template &lt;class Element, unsigned long max_size&gt; class Storage { public: Storage(Element) {} }; template &lt;class Element&gt; class Storage &lt;Element, 0 /* unlimited*/&gt; { public: Storage(Element e) {} }; template &lt;unsigned long max_size&gt; class Storage &lt;int, max_size&gt; { public: Storage(int e) {} }; template &lt;&gt; class Storage&lt;char*, 0&gt; { public: Storage(char* s) {} }; template &lt;&gt; class Storage&lt;char*, 100&gt; { public: Storage(char* s) {} }; int main() { int p1=4; Storage&lt;int, 5&gt; st1(p1); Storage&lt;char*, 100&gt; st2(char* s); Storage&lt;double, 80000&gt; st3(double n); Storage&lt;double, 0&gt; st4(double n); return 0; } //====================== end of sample.cpp ========================== </pre> Какой из шаблонов Storage в файле sample.cpp не задействован в функции main в файле sample.cpp?
<pre>//====================== start of sample.cpp ========================== #include &lt;vector&gt; class ServiceOrganization; class Building { static char* m_city; const unsigned int m_high_size; std::vector&lt;int&gt; m_flats; unsigned int m_square; ServiceOrganization&amp; m_organization; public: Building(); }; int main() { Building house; return 0; }//====================== end of sample.cpp ========================== </pre> Какие члены класса Building из файла sample.cpp обязательно должны быть инициализированы в списке инициализации?
<pre>//====================== start of sample.cpp ========================== #include &lt;vector&gt; class Person { public: short m_age; const char* m_name; const char* m_surname; const char* m_region_name; }; class Region { public: const char* region_name; const char* cheef_name; long size; }; int main() { std::vector&lt;unsigned char&gt;* mybuffer = new std::vector&lt;unsigned char&gt;(sizeof(Person) + sizeof(Region), 0); Person* my_person = new (&amp;(mybuffer->at(0))) Person(); my_person-&gt;~Person(); delete my_person; Region* p_region = new (&amp;(mybuffer-&gt;at(0))) Region(); p_region-&gt;~Region(); delete p_region; delete mybuffer; return 0; }//====================== end of sample.cpp ========================== </pre> Какие операции освобождений ресурсов в файле sample.cpp являются лишними или ошибочными?
<pre> //====================== start of sample.cpp ========================== #include &lt;type_traits&gt; template &lt;typename IT_1, typename IT_2, bool b&gt; IT_2 copy_imp(IT_1 first, IT_1 last, IT_2 out, const std::integral_constant&lt;bool, b&gt;&amp;) { while(first != last) { *out = *first; ++out; ++first; } return out; } template &lt;typename T&gt; T* copy_imp(const T* first, const T* last, T* out, const std::true_type&amp;) { memmove(out, first, (last-first)*sizeof(T)); return out * (last-first); } template &lt;typename I1, typename I2&gt; inline I2 copy(I1 first, I1 last, I2 out) { typedef typename std::iterator_traits&lt;I1&gt;::value_type value_type; return copy_imp(first, last, out, std::has_trivial_assign<value_type>()); } class A {}; int main() { std::vector&lt;short&gt; arr1; std::vector&lt;short&gt; arr2; copy(arr1.begin(), arr1.end(), arr2.begin()); return 0; } //====================== end of sample.cpp ========================== </pre> Какие утверждения про используемую функцию копирования copy_impl() верны?