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

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

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

<pre> //====================== start of sample.cpp ========================== template &lt;typename T&gt; class multiplies: public binary_function&lt;T,T,T&gt; { public: T operator() (const T&amp; x, const T&amp; y) const { return x * y; } }; //====================== end of sample.cpp ========================== </pre> Какие утверждения про приведённый выше код функтора multiplies верны?

(Ответ считается верным, если отмечены все правильные варианты ответов.)

Варианты ответа
содержащегося кода "operator()" недостаточно, должны быть реализованы ещё некоторые операторы
наследование от шаблона binary_function позволяет получить типы для "саморефлексии"(Верный ответ)
приведённый функтор может быть использован для передачи выполняемой операции в функции алгоритмов(Верный ответ)
код операции умножения может быть заменён на любые другие арифметические или логические операции(Верный ответ)
Похожие вопросы
<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&lt;value_type&gt;()); } class A {}; int main() { std::vector&lt;A&gt; vec1; std::vector&lt;A&gt; vec2; copy(vec1.begin(), vec1.end(), vec2.begin()); return 0; } //====================== end of sample.cpp ========================== </pre> Какие утверждения про то какая функция копирования copy_impl() будет использована верны?
<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() верны?
<pre> //====================== start of sample.cpp ========================== template&lt;unsigned long N&gt; class binary { public: static unsigned long const value = binary&lt;N / 10&gt;::value &lt;&lt; 1 | N % 10; }; template&lt;&gt; class binary&lt;0&gt; { public: static unsigned long const value = 0; }; template&lt;&gt; class binary&lt;1&gt; { public: static unsigned long const value = 1; }; int main(int argc, char* argv[]) { static unsigned const x0 = binary&lt;0&gt;::value; static unsigned const x1 = binary&lt;1000&gt;::value; static unsigned const x2 = binary&lt;1001&gt;::value; static unsigned const x3 = binary&lt;1010&gt;::value; static unsigned const x4 = binary&lt;1011&gt;::value; return 0; } //====================== end of sample.cpp ========================== </pre> При инициализации какой переменной не будет использоваться конкретизация шаблона с параметром 0?
<pre>//====================== start of sample.cpp ========================== #include &lt;stdio.h&gt; class Region; class Person { public: short m_age; const char* m_name; const char* m_surname; const char* m_region_name; Person(const char* name) : m_name(name) {} operator short () {return m_age;} operator const char* () {return &quot;&quot;;} }; class Region { public: const char* region_name; const char* cheef_name; long size; Region(const char* region_nm = &quot;&quot;) : region_name(region_nm) {} operator long () {return size;} operator const char* () {return region_name;} }; int main() { Person p1(&quot;Vasily Ivanov&quot;); Region r; printf(&quot;Region number %u, driver %s&quot;, static_cast&lt;unsigned short&gt;(r), static_cast&lt;const char*&gt;(p1)); return 0; }//====================== end of sample.cpp ========================== </pre> Какие из имеющихся в файле sample.cpp конструкторов и операторов преобразования задействованы в операциях в функции main()?
<pre> //====================== start of sample.cpp ========================== template &lt;typename ForwardIterator, typename T&gt; void replace ( ForwardIterator first, ForwardIterator last, const T&amp; x, const T&amp; y) { while(first != last) { if (*first == x) *first = y; ++first; } return first; } //====================== end of sample.cpp ========================== </pre> Каковы требования к итераторам, участвующим в алгоритме replace(), имплементация которого приведена выше, корректны?
<pre>//====================== start of sample.cpp ========================== class Region; class Person { public: short m_age; const char* m_name; const char* m_surname; const char* m_region_name; Person(const char* name) : m_name(name) {} operator short () {return m_age;} operator const char* () {return &quot;&quot;;} operator Region* (); }; class Region { public: const char* region_name; const char* cheef_name; long size; Region(const char* region_nm) : region_name(region_nm) {} operator long () {return size;} operator const char* () {return region_name;} operator Person () {return Person(cheef_name);} }; Person::operator Region* () {return new Region(m_region_name);}//====================== end of sample.cpp ========================== </pre> Какие операторы преобразования класса Person не являются корректными с точки зрения архитектуры?
<pre> //====================== start of sample.cpp ========================== struct A { A(); virtual ~A(); private: A(A&amp;a); A&amp; operator=(const A&amp; a); }; struct B: public A {}; struct C {}; struct D { D(); D&amp; operator=(const D&amp; d); }; //====================== end of sample.cpp ========================== </pre> Какие из типов из файла sample.cpp удовлетворяют требованию CopyConstructible?
<pre> //====================== start of sample.cpp ========================== template&lt;unsigned long N&gt; class binary { public: static unsigned long const value = binary&lt;N / 10&gt;::value &lt;&lt; 1 | N % 10; }; template&lt;&gt; class binary&lt;0&gt; { public: static unsigned long const value = 0; }; int main(int argc, char* argv[]) { static unsigned const xyz = binary&lt;111&gt;::value; return 0; } //====================== end of sample.cpp ========================== </pre> Конкретизация шаблона с значением 111 приводит:
<pre> //====================== start of sample.cpp ========================== class User { public: struct Region { short country_code; short city_code; static char* city_name; }; const char* name; int age; double balance; Region region; const char* get_name() const { return (*this).name; } int get_age() const { return this-&gt;age; } double get_balance() const { return (*this)-&gt;balance; } short get_country_code() const { return Region::country_code; } short get_city_code() const { return region.city_code; } const char* get_city_name() const { return Region::city_name; } }; //====================== end of sample.cpp ========================== </pre> В каких методах обращения к членам объекта класса user типа User корректны?
<pre> //====================== start of sample.cpp ========================== template&lt;unsigned long N&gt; class binary { public: static unsigned long const value = binary&lt;N / 10&gt;::value &lt;&lt; 1 | N % 10; }; template&lt;&gt; class binary&lt;0&gt; { public: static unsigned long const value = 0; }; int main(int argc, char* argv[]) { if (argc &gt; 1) { static unsigned const two = binary&lt;10&gt;::value; } return 0; } //====================== end of sample.cpp ========================== </pre> Когда будет посчитано значение переменной two?