8 questions. Covers Lambdas.
Questions 1 to 5 of 8
cpp #include <algorithm> #include <iostream> #include <vector> int main() { std::vector<int> v{59, 60, 61, 100, 0}; int n = std::count_if(v.begin(), v.end(), [](int s) { return s >= 60; }); std::cout << n << '\n'; }
cpp #include <iostream> int main() { int n = 10; auto f = [n](int k) mutable { n += k; return n; }; f(1); std::cout << f(2) << ' ' << n << '\n'; }
cpp #include <iostream> class Account { public: inline static int opened = 0; explicit Account(int cents) : cents_(cents) { ++opened; } static Account withBonus(int cents) { return Account(cents + 500); } int cents() const { return cents_; } private: int cents_; }; int main() { Account a(100); Account b = Account::withBonus(250); std::cout << b.cents() << ' ' << Account::opened << '\n'; }
static
static Account withBonus(int cents)
this
main
auto addToTotal = [&total](int n) { total += n; };
&total
total
5 question(s) left on this page.