С++ для интервью
37 subscribers
10 photos
Готовься к собеседованиям по C++ эффективно: реальные вопросы, типичные HR уловки, примеры кода и объяснения.
Каждый пост — один шаг ближе к офферу 💼
Download Telegram
🔍 RAII и исключения

void f() {
std::lock_guard<std::mutex> g(m);
throw std::runtime_error("error");
}
Please open Telegram to view this post
VIEW IN TELEGRAM
🌃 virtual деструктор

struct Base {
~Base() = default;
};

struct Derived : Base {
~Derived() { std::cout << "dtor\n"; }
};

Base* b = new Derived;
delete b;
Please open Telegram to view this post
VIEW IN TELEGRAM
💻 std::vector и инвалидирование

std::vector<int> v = {1,2,3};
auto it = v.begin();
v.push_back(4);
Please open Telegram to view this post
VIEW IN TELEGRAM
👍4
❔ CRTP vs virtual

CRTP (Curiously Recurring Template Pattern) — идиома проектирования, при которой шаблон класса принимает производный класс в качестве параметра шаблона

template<typename D>
struct Base
{
void call() { static_cast<D*>(this)->impl(); }
};
Please open Telegram to view this post
VIEW IN TELEGRAM
👍4
🤯 Работа с auto
int x = 10;
auto f() { return (x); }
Please open Telegram to view this post
VIEW IN TELEGRAM
Что вернёт f()?
Anonymous Quiz
80%
int
0%
int&
20%
const int&
👍4
🔍 Есть ли ошибка в коде ниже?
std::string_view f() {
return std::string("hello");
}
Please open Telegram to view this post
VIEW IN TELEGRAM
std::unique_ptr и move
std::unique_ptr<int> a = std::make_unique<int>(5);
auto b = a;
🍿 Как поведет себя функция?
int x = 10;
auto f = [=]() mutable { ++x; };
f();
Please open Telegram to view this post
VIEW IN TELEGRAM
Работа с constexpr
constexpr int f(int x) { return x * 2; }
int y = f(10);
👍5
Концепция SFINAE
template<class T>
auto f(T t) -> decltype(t.size()) {}
👍3