🕹️
Game Engine. hardCORE series
Udemy course / C++PatreonBoostyTelegramYouTube
  • 💻Lectures
    • 00. Promo
    • 01. What is game engine?
    • 02. C++ build process. Preprocessing
      • Preprocessor commands
      • Code
    • 03. C++ build process. Compilation Theory. Assembly
      • Compiler commands
      • Code
    • 04. C++ build process. Compiler optimizations
      • Compiler commands
      • Code
    • 05. C++ build process. Linker. Forward declaration
      • Compiler commands
      • Code
    • 06. C++ build process. Linker. Static and Dynamic libraries. PCH
      • Compiler commands
      • Code
      • Books
    • 07. СMAKE. Day1. Basics
      • CMAKE commands
      • Repository
    • 08. СMAKE. Day2. Libs
      • CMAKE commands
      • Repository
    • 09. Conan. C++ package manager
      • Conan commands
      • Repository
    • 10. Raylib. CMAKE additional topics
      • Repository
    • 11. Doodle Jump Game. Raylib. CMAKE pch and other topics
      • Repository
    • 12. Conan and CMAKE integration. Github workflows
      • Commands
      • Repository
    • 13. Engine. Layout
    • 14. Engine. Logging
    • 15. Engine. Window
    • 16. Engine. Window events. Input
  • Мои курсы
    • 🎮Unreal Engine — полное руководство по разработке на С++
    • 🧪Автоматизация и тестирование в Unreal Engine
    • 🔊Metasounds
    • 🏗️Design patterns
    • 🐍Snake game
    • 🧠OpenAI
  • LifeEXE сообщество
    • Ресурсы
Powered by GitBook
On this page
  • Math
  • Weapon
  • Character
  • Main
  1. Lectures
  2. 05. C++ build process. Linker. Forward declaration

Code

Math

// Math.h
#pragma once

int max(int x, int y);
int factorial(int n);
int sum(int n);
// Math.cpp
int max(int x, int y)
{
    return x > y ? x : y;
}

int factorial(int n)
{
    return n <= 1 ? 1 : n * factorial(n - 1);
}

int sum(int n)
{
    return n <= 0 ? 0 : n + sum(n - 1);
}

Weapon

// Weapon.h
#pragma once

class Weapon
{
public:
    Weapon();
    void fire();

private:
    int m_bullets{ 23 };
};
// Weapon.cpp
#include "Weapon.h"

Weapon::Weapon()
{

}

void Weapon::fire()
{
    if (m_bullets <= 0) return;
    --m_bullets;
}

Character

// Character.h
#pragma once

class Weapon;

class Character
{
public:
    Character(const char* name);
    ~Character();

    void f1(Weapon*);
    void f2(Weapon&); 
    void f3(const Weapon&);
    Weapon f4();
    void f5(Weapon);

private:
    const char* m_name;
    Weapon* m_weapon;
};
// Character.cpp
#include "Character.h"
#include "Weapon.h"
#include <iostream>

Character::Character(const char* name) : m_name(name)
{
    m_weapon = new Weapon();
    m_weapon->fire();

    std::cout << sizeof(Weapon) << std::endl;
    std::cout << sizeof(Weapon*) << std::endl;
    std::cin.get();
}

Character::~Character()
{
    delete m_weapon;
    m_weapon = nullptr;
}

void Character::f1(Weapon*)
{
}

void Character::f2(Weapon&)
{
}

void Character::f3(const Weapon&)
{
}

Weapon Character::f4()
{
    return Weapon();
}

void Character::f5(Weapon)
{
}

Main

// main.cpp
#include "Character.h"

int main() {
    const Character character("Nux");
    // int counter = 10;
    // counter %= 0;
    return 0;
}
PreviousCompiler commandsNext06. C++ build process. Linker. Static and Dynamic libraries. PCH

Last updated 9 months ago

💻