Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

classes-basics

Classes basics

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Classes basics: the syntax, patterns, and safety habits you need before advancing in C++.

OOP in C++ is value-centric—constructors, destructors, and RAII show up in every game engine and trading codebase.

You will apply Classes basics in contexts like: UI toolkits, simulation cores, and plugin architectures with polymorphic interfaces.

Write C++ in main.cpp with int main(), click Run on server—the dev runner compiles with c++/g++ -std=c++17 -Wall and runs the binary; read template errors in stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

A class bundles data and behavior—similar to Java classes but with value semantics, stack allocation, and manual control over copying when you need it.

Minimal class

class Point {
public:
    int x = 0;
    int y = 0;
    void translate(int dx, int dy) {
        x += dx;
        y += dy;
    }
};

Member functions receive a hidden this pointer to the current object.

Important interview questions and answers

  1. Q: class vs struct?
    A: Default access differs (private vs public); otherwise equivalent.
  2. Q: Stack vs heap objects?
    A: Point p; on stack; auto p = std::make_unique<Point>(); on heap with RAII.

Self-check

  1. What does the this pointer refer to?
  2. Default access for class members?

Tip: Default to private data with public methods—encapsulation like Java, but watch value vs reference semantics.

Interview prep

class vs struct?

Default member access differs—private for class, public for struct; otherwise equivalent.

What is this?

Pointer to the current object inside non-static member functions.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Class vs struct?
  • Member init?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump