Search
Z testu je možné získat maximálně 30 bodů, 15 bodů z obsáhlejších otázek na této stránce a 15 bodů z krátkých otázek.
class object { public: object() { std::cout << "1 "; } object(const object&) { std::cout << "2 "; } object& operator=(const object&) { std::cout << "3 "; return *this; } object(object&&) { std::cout << "4 "; } object& operator=(object&&) { std::cout << "5 "; return *this; } ~object() { std::cout << "6 "; } }; void foo(object x) { std::cout << "foo! "; } int main() { object o1; object o2; object o3 = std::move(o2); foo(o3); o1 = o2; }
1 1 4 2 foo! 6 3 6 6 6
template <typename T> class array { public: array(T* data, std::size_t length) : elements{ new T[len] }, len{ length } { for (int i = 0; i < len; ++i) { elements[i] = data[i]; } } private: T* elements; std::size_t len; };
len
void foo() { std::vector<int> vec = { 1, 2, 3, 2, 3, 7, 7, 5, 2 }; int i = 0; std::for_each(begin(vec), end(vec), [i](int elem) mutable { static int temp = 0; temp += elem % 3; i += temp + elem % 4; }); std::cout << i << std::endl; }
0
i
stack<T>
int main() { stack<int> s1; stack<int> s2; s1.push(12); s1.push(13); s1.push(17); s2 = s1; while (!s2.empty()) { int temp = s2.top(); s2.pop(); std::cout << temp << std::endl; } std::cout << std::boolalpha << s1.empty() << std::endl; }
Očekávaný výstup je 17 13 12 False
template <typename T> class stack { public: void push(const T&); void pop(); T& top(); bool empty() const; // ty dal uz nejsou nutne const T& top() const; stack(); stack(const stack&); stack& operator=(const stack&); };
template <typename T, typename U> class Pair { T first; U second; friend ostream& operator<<(std::ostream&, const Pair&); }; ostream& operator<<(std::ostream& out, const Pair& p){ out << p.first << ' ' << p.second; return out; }