💻 Programming

C++

C Plus Plus

A high-performance systems programming language. Used in game engines, operating systems, and browsers. An extension of C.

📖 Detailed Explanation

C++ is a general-purpose programming language developed by Danish computer scientist Bjarne Stroustrup at Bell Labs in 1979. It originally started under the name "C with Classes" and is characterized by adding object-oriented programming features while maintaining the efficiency of the C language.

C++ is a multi-paradigm language that supports both low-level memory manipulation and high-level abstraction. It supports procedural, object-oriented, generic, and functional programming, and follows the philosophy "You don't pay for what you don't use (zero-overhead abstraction)."

Key features of C++ include classes and inheritance, generic programming through templates, the RAII (Resource Acquisition Is Initialization) pattern, operator overloading, and multiple inheritance. Since C++11, modern features such as lambda expressions, smart pointers, and move semantics have been added extensively.

In practice, C++ is widely used in performance-critical fields such as game engines (Unreal Engine, Unity core), operating systems (Windows, parts of the Linux kernel), web browsers (Chrome, Firefox), databases (MySQL, MongoDB), embedded systems, and high-frequency trading systems. As of 2025, it consistently ranks near the top of the TIOBE Index, and the core engines of TensorFlow and PyTorch in the AI/ML field are also written in C++.

💻 Code Example

// 1. 기본 클래스와 생성자/소멸자
#include <iostream>
#include <string>
#include <memory>
#include <vector>

class Animal {
protected:
    std::string name;
public:
    Animal(const std::string& n) : name(n) {}
    virtual ~Animal() = default;
    virtual void speak() const = 0;  // 순수 가상 함수
};

class Dog : public Animal {
public:
    Dog(const std::string& n) : Animal(n) {}
    void speak() const override {
        std::cout << name << "가 멍멍 짖습니다!" << std::endl;
    }
};

// 2. 템플릿과 스마트 포인터
template<typename T>
class Container {
private:
    std::vector<T> items;
public:
    void add(T item) { items.push_back(std::move(item)); }
    size_t size() const { return items.size(); }
    const T& get(size_t index) const { return items.at(index); }
};

// 3. 람다와 알고리즘 (C++11/14/17)
#include <algorithm>

int main() {
    // 스마트 포인터로 메모리 자동 관리
    auto dog = std::make_unique<Dog>("바둑이");
    dog->speak();  // 출력: 바둑이가 멍멍 짖습니다!

    // 템플릿 컨테이너 사용
    Container<int> numbers;
    numbers.add(10);
    numbers.add(20);
    std::cout << "크기: " << numbers.size() << std::endl;

    // 람다와 STL 알고리즘
    std::vector<int> vec = {5, 2, 8, 1, 9};
    std::sort(vec.begin(), vec.end(), [](int a, int b) {
        return a < b;  // 오름차순 정렬
    });

    // 범위 기반 for 루프
    for (const auto& num : vec) {
        std::cout << num << " ";  // 출력: 1 2 5 8 9
    }

    return 0;
}

🗣️ Say It Like This in Practice

💬 In a Meeting
"This module is performance-critical, so it would be good to write it in C++. If we provide the Python bindings with pybind11, it can also be easily integrated with the existing ML pipeline."
💬 In an Interview
"In C++, smart pointers implement the RAII principle. unique_ptr represents exclusive ownership and shared_ptr represents shared ownership, and they automatically free memory through reference counting. The circular reference problem can be solved with weak_ptr."
💬 In a code review
"Here, it would be better to use std::unique_ptr instead of a raw pointer. There is a possibility of memory leaks when an exception occurs, and ownership also becomes clear. Also, taking it by const reference lets you avoid unnecessary copies."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Memory Leaks and Dangling Pointers

Failing to delete memory allocated with new, or accessing freed memory, causes critical bugs. Where possible, use smart pointers (unique_ptr, shared_ptr), and use raw pointers only for non-owning observation.

❌
Undefined Behavior

Out-of-bounds array access, null dereferencing, and use of uninitialized variables cause UB. Enable compiler warnings (-Wall -Wextra) and perform runtime checks with tools such as AddressSanitizer.

✅
Applying Modern C++ Style

Make active use of the modern features of C++11/14/17/20. auto type deduction, range-based for, lambdas, move semantics, std::optional, std::string_view, and the like make code safer and more efficient.

🔗 Related Terms

📚 Learn More