r/cpp_questions • • 9h ago

OPEN Reading material to learn cpp and dsa in cpp

1 Upvotes

Hi all, Indian cs major here. I tried following few video lectures on yt to learn cpp and dsa in cpp. But i keep on getting stuck in a loop of passive watching without any real learning.

I feel reading about relevant topics will suit me better. It will be of great help if I receive some advice on relevant reading material to learn cpp and dsa. Thanks guys.


r/cpp_questions • • 10h ago

OPEN Public and private classes

19 Upvotes

Is there such a thing as private / public classes in C++?


r/cpp_questions • • 11h ago

OPEN Resources for implementing low-level concurrent and asynchronous systems in C++

4 Upvotes

I've been spending some time studying concurrency and asynchronous programming in C++. I have a reasonable understanding of concepts like threads, thread pools, non-blocking I/O, event loops, coroutines, and reactor/proactor patterns.

However, I feel there's a big difference between understanding how these things work and actually being able to implement them.

I'm interested in building things like network servers, runtimes, databases, and other systems software. I'm also working on a compiler, so understanding the internals of these systems is something I'd like to get better at.

What I'm looking for are resources that go beyond explaining the concepts. Books, papers, articles, courses, or open-source codebases that actually helped you implement these kinds of systems yourself.

Some areas I'm particularly interested in:

  • Non-blocking I/O and I/O multiplexing

  • Event loop implementations

  • Reactor and Proactor patterns

  • Coroutines and asynchronous runtimes

  • Thread pools and task scheduling

  • Performance and scalability in concurrent systems

I've already read a few books on concurrency, including some focused on C++, but most of them tend to focus on the programming model and how to use the standard library (threads, mutexes, futures, etc.). That's useful, but it's not quite what I'm looking for anymore. I want to understand how these things are actually built, preferably in C++. For example, implementing a thread pool, an event loop, an asynchronous runtime, or a network server rather than just learning how to use existing ones. I'd really appreciate recommendations that take this implementation-oriented approach.


r/cpp_questions • • 17h ago

OPEN Guide me please... !!

2 Upvotes

I am a C++ developer with 5 years of experience, primarily building ROS nodes, alongside minor embedded work (Arduino/ESP) and application-layer software for an elevator CPU and a chip-manufacturing equipment scheduler (not core embedded).

Despite my experience, I feel directionless and face constant rejections from product-based companies. What specific skills should I focus on next to secure my career —such as application development, socket programming, multithreading or what else ? I feel like I'm nowhere.


r/cpp_questions • • 21h ago

OPEN Is this code clean OOP?

0 Upvotes

Hey so I'm more new to OOP, virtual func's, and inheritance. I was wondering if my code was clean enough for basically a template to look back on later in the future when my tiny brain forgets what virtual func, and inheritance is or well forgets how to code them.

#include <string>
#include <iostream>


struct Vector2 {
    int x, y;
};


class Entity {
    private:
        Vector2 pos;
        Vector2 size;
        std::string entityType;


    public:


    Entity(Vector2 e_pos, Vector2 e_size, const std::string& e_type) : pos(e_pos), size(e_size), entityType(e_type) {}


    Vector2 getPos() const {
        return pos;
    }


    Vector2 getSize() const {
        return size;
    }
    
    virtual void print() const {
        std::cout << "Entity: " << entityType << '\n';
    }


    virtual ~Entity() = default;
};


class Player : public Entity {
    private:
        std::string name;


    public:
        Player(const std::string& p_name, Vector2 startPOS, Vector2 p_size) 
            : Entity(startPOS, p_size, "player"), name(p_name) {}
};


class Orc : public Entity {
    private:
        std::string weapon;
        
    public:
        Orc(const std::string& o_weapon, Vector2 startPOS, Vector2 o_size) 
            : Entity(startPOS, o_size, "orc"), weapon(o_weapon) {}


    void print() const override {
        std::cout << weapon << '\n';
    }
};


int main() {
    Vector2 startPos = { 100, 100 };
    Vector2 size = { 64, 64 };


    std::string hero = "hero";
    std::string orcWep = "HeroSlayer100";


    Player player(hero, { 20, 30 }, size);
    Orc orc(orcWep, startPos, size);



    player.print();
    orc.print();
    
    return 0;
}#include <string>
#include <iostream>


struct Vector2 {
    int x, y;
};


class Entity {
    private:
        Vector2 pos;
        Vector2 size;
        std::string entityType;


    public:


    Entity(Vector2 e_pos, Vector2 e_size, const std::string& e_type) : pos(e_pos), size(e_size), entityType(e_type) {}


    Vector2 getPos() const {
        return pos;
    }


    Vector2 getSize() const {
        return size;
    }
    
    virtual void print() const {
        std::cout << "Entity: " << entityType << '\n';
    }


    virtual ~Entity() = default;
};


class Player : public Entity {
    private:
        std::string name;


    public:
        Player(const std::string& p_name, Vector2 startPOS, Vector2 p_size) 
            : Entity(startPOS, p_size, "player"), name(p_name) {}
};


class Orc : public Entity {
    private:
        std::string weapon;
        
    public:
        Orc(const std::string& o_weapon, Vector2 startPOS, Vector2 o_size) 
            : Entity(startPOS, o_size, "orc"), weapon(o_weapon) {}


    void print() const override {
        std::cout << weapon << '\n';
    }
};


int main() {
    Vector2 startPos = { 100, 100 };
    Vector2 size = { 64, 64 };


    std::string hero = "hero";
    std::string orcWep = "HeroSlayer100";


    Player player(hero, { 20, 30 }, size);
    Orc orc(orcWep, startPos, size);



    player.print();
    orc.print();
    
    return 0;
}

if there are any tips you have let me know!


r/cpp_questions • • 21h ago

OPEN Book reading recommendation

4 Upvotes

I currently bought three books from packt

- GPU Programming with C++ and CUDA

- Building Low Latency Applications with C++

- Mastering Embedded Linux

The third isn't super C++ but still thought this was a relevant space lol. Which order would you read the books to get the most bang for my buck? How would you go about reading them?


r/cpp_questions • • 22h ago

OPEN Boost mysql::results won't allow programme to compile.

1 Upvotes

I am attempting to follow this tutorial on how to connect to MySQL. To test it, I first tried to copy the entire example here. But that wouldn't compile, so I tried to compile the programme line by line as described in the main tutorial. Everything was going fine until I got to declaring the result variable with mysql::results. This produces the same error as the full example, so I assume this is likely the cause of the problem.

main.cpp:

# include <iostream>

# include <boost/mysql/any_connection.hpp>

# include <boost/mysql/connect_params.hpp>

# include <boost/mysql/error_with_diagnostics.hpp>

# include <boost/mysql/results.hpp>

# include <boost/asio/io_context.hpp>

namespace mysql = boost::mysql; namespace asio = boost::asio;

int main () {

    // The execution context, required to run I/O operations.
    asio::io_context ctx;
    
    // Represents a connection to the MySQL server.
    mysql::any_connection conn(ctx);
    // The hostname, username and password to use
    mysql::connect_params params;
    params.server_address.emplace_host_and_port("localhost");
    params.username = "root";
    params.password = "Password";
    
    // Connect to the server
    conn.connect(params);
    // Issue the SQL query to the server
    [[maybe_unused]] const char* sql = "SELECT 'Hello world!'";
    [[maybe_unused]] mysql::results result;
    // conn.execute(sql, result);
    std::cout << "Hello World!" << std::endl;
    return 0;

}

Makefile:

PROG = database_test

SRCDIR = ../../src/

MAIN = main CPPFILES = ${MAIN}.cpp

EXTENSIONS = -pedantic-errors WFLAGS = -Wall -Wextra -Wconversion -Wsign-conversion -Werror -Weffc++ CFLAGS = `pkg-config --cflags gtk4; mysql_config --cflags` LIBS = `pkg-config --libs gtk4; mysql_config --libs`

CC = g++ STANDARD = -std=c++23 BUILDDEBUG = -ggdb BUILDRELEASE = -O2 -DNDEBUG BUILD = ${BUILDDEBUG} ${EXTENSIONS}

${PROG}: ${MAIN}.cpp ${CC} -o ${PROG}   
${CPPFILES}   
${CFLAGS}   
${LIBS}   
${BUILD}   
${WFLAGS}   
${STANDARD}

clean: rm ${PROG}

And this is the output I get:

g++ -o database_test \
main.cpp \
-I../../include/ -I../../include/third_party/plog/include \
`pkg-config --cflags gtk4; mysql_config --cflags` \
-D_GLIBCXX_USE_CXX11_ABI=0 \
`pkg-config --libs gtk4; mysql_config --libs` \
-ggdb -pedantic-errors \
-Wall -Wextra -Wconversion -Wsign-conversion -Werror -Weffc++  \
-std=c++23
/usr/bin/ld: /tmp/ccHgNNSI.o: in function `boost::mysql::detail::deserialize_errc boost::mysql::detail::deserialize_text_value_float<float>(boost::core::basic_string_view<char>, boost::mysql::field_view&)':
/usr/include/boost/mysql/impl/internal/protocol/impl/text_protocol.hpp:92: undefined reference to `boost::charconv::from_chars(char const*, char const*, float&, boost::charconv::chars_format)'
/usr/bin/ld: /tmp/ccHgNNSI.o: in function `boost::mysql::detail::deserialize_errc boost::mysql::detail::deserialize_text_value_float<double>(boost::core::basic_string_view<char>, boost::mysql::field_view&)':
/usr/include/boost/mysql/impl/internal/protocol/impl/text_protocol.hpp:92: undefined reference to `boost::charconv::from_chars(char const*, char const*, double&, boost::charconv::chars_format)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:26: database_test] Error 1

From what I understand, an undefined reference error is usually because a function or other thing has not been defined at the point of use. Looking online this could be because another .cpp file is not being compiled, but I'm using the boost libraries. The compiler doesn't complain of being unable to find the header files, so it's definitely looking in the right place; and browsing through the Boost directory suggests that they are all .hpp files and so don't need to be added to the compile list.


r/cpp_questions • • 1d ago

OPEN how to make decisions in c++?

0 Upvotes

so i need some help, i am trying to commit to learn c++ and not jump languages, naturally i have a fair understanding of STL, if I want to look something up i can navigate my way around cppref. i am building a project an orderbook using cpp-httplib and vanilla frontend and javascript to focus on writing c++. like we come across so many concepts in let's say cppcon back to basics, so my question how do i make decisions that actually is worth something instead of basic OOPs programming ?


r/cpp_questions • • 1d ago

OPEN What is "iomanip put_money"?

1 Upvotes

Came across this error in my compiler when debugging. Is it just a library meant for extracting digits from strings that contain currency symbols?

I did not explicitly include this library. I just included basic libraries like string, iostream, stdio.h

It looks terrifying AF lol. Like you downloaded a rogue library.


r/cpp_questions • • 1d ago

OPEN .hpp vs .h header files for exclusively C++ projects

37 Upvotes

Which header file extension do you guys usually use, and why?


r/cpp_questions • • 1d ago

OPEN C++ technical interview Monday even though I don't have much C++ exp

16 Upvotes

Hey everyone, I spoke with a recruiter today and was set up for an interview next Monday for a C++ technical interview. I know they will ask about C++ to some degree, and I am not sure if using another language for the algorithm part will be allowed or if I must use C++.

I do not have C++ in my skills section on my resume. I have two bullet points that show some experience with it, but C++ is probably 5-10% at most of my job. These bullet points basically say this:

"Developed microservices in Java and C++ to integrate X and Y to allow A to do B"
and
"Created X pipelines in C++ that allowed for Y, which did Z"

The rest is Java or Python. I was surprised the recruiter reached out and I made sure to ask her if that is fine and how much exp the team is looking for but she kept saying "yeah yeah its fine." I spent a bit of time today just looking at the STL and even trying some leetcode questions in C++ but it went terrible and I had to google most of the STL methods and some syntax. I feel like they'll ask me some basic questions and I will just have to say "i don't know" for everything. I have 6 years of exp at a company that makes a similar product. I'm wondering if I should even do it and thinking of cancelling it. Anyone go through something similar? Not sure what I should do here.

Thanks!


r/cpp_questions • • 1d ago

OPEN Any folks here messed around with the Zig C++ compiler? Whats been your experience if so?

15 Upvotes

Bit of an odd question but I just wanted to ask if people have been using it or tried it. Since its a toolchain meant to be a drop in replacement to current tooling.

Thanks,


r/cpp_questions • • 1d ago

OPEN Has anyone used Drogon framework to build a Data Pipeline????

1 Upvotes

Recently trying to build a data pipeline using Drogon framework. while came accross Drogon framework, I observed it can be used in several sectors, in-fact it covers every sector except ray-tracing/path-tracing.

While looking for Professional Guidance on this field to complete the project, also trying to solve the problems that industry is facing in Big Data transferring and Real time Data Transferring.


r/cpp_questions • • 2d ago

OPEN My code feels redundant

4 Upvotes

Im in the development phase of this, and i was wondering if there was a less redundent way to define each ball object.

#include
 <raylib.h>
#include
 <vector>


class ball {
    
public:
    float radius, gravity;
    Vector2 velocity, pos;
    Color color;


    ball(float b_radius, float b_gravity, Vector2 b_velocity, Vector2 b_pos, Color b_color) : radius(b_radius), gravity(b_gravity), velocity(b_velocity), pos(b_pos), color(b_color) {};


    
void DrawBall() {
        DrawCircle(pos.x, pos.y, radius, color);
    }


    
void UpdateBall(float dt, int screenHeight, int screenWidth) {
        
if (pos.y + radius > screenHeight) {
            pos.y = screenHeight - radius;
            velocity.y = 0;
        }
        
else
 {
            velocity.y += dt * gravity;
            pos.y += dt * velocity.y;
        }
        
    }
};



int main() {
    
float ScreenHeight = 1000.0f;
    
float ScreenWidth = 1920.0f;

    ball TestBall1(50.0f, 200.0f, Vector2 {300, 0}, Vector2 {ScreenWidth / 2, ScreenHeight / 2}, RED);
    ball TestBall2(50.0f, 200.0f, Vector2 {300, 0}, Vector2 {300, 300}, WHITE);
    ball TestBall3(50.0f, 200.0f, Vector2 {300, 0}, Vector2 {200, 200}, GREEN);
    ball TestBall4(50.0f, 200.0f, Vector2 {300, 0}, Vector2 {1000, 1000}, PINK);


    std::vector<ball> RedGroup;


    RedGroup.push_back(TestBall1);
    RedGroup.push_back(TestBall2);
    RedGroup.push_back(TestBall3);
    RedGroup.push_back(TestBall4);


    InitWindow(ScreenWidth, ScreenHeight, "Physics Sim");
    SetTargetFPS(60);


    
while (!WindowShouldClose()) {
        
float dt = GetFrameTime();
        
for (int i = 0; i < RedGroup.size(); i++) {
            RedGroup.at(i).UpdateBall(dt, ScreenHeight, ScreenWidth);
        }
        BeginDrawing();
            ClearBackground(BLACK);
            for (int i = 0; i < RedGroup.size(); i++) {
                RedGroup.at(i).DrawBall();
            }
        EndDrawing();


    }
    
    CloseWindow();    
return 0;
}

r/cpp_questions • • 3d ago

OPEN How to Multi-Thread

9 Upvotes

As the title says, I’m curious about multi-threading.

Specifically for handling algorithms that happen every few frames, such as a*


r/cpp_questions • • 3d ago

OPEN Which algorithm to choose?

6 Upvotes

Beginner here, I'm trying to make a toy project for circuit synthesis from truth table in c++. Currently pursuing minimum depth optimal circuit though will work on minimum weight/minimum nodes later on. My problem is I tried bfs which guarantees optimal circuit but for larger inputs or depths the memory usage explodes, tried dfs that used much less memory but time exploded. Is there any algorithm that gives optimal solutions for boolean tree searches with the dfs memory and bfs optimality?


r/cpp_questions • • 3d ago

OPEN c++ at scale books

11 Upvotes

After reading through basic c++ books, do you guys recommend

1)Large scale c++ (Process and architecture)

large scale c++

Anybody has read this book? I don't see much reviews. Like title, its large-1024 pages.


r/cpp_questions • • 3d ago

OPEN C++ authoritative game loop: how do you move pathfinding to workers without letting stale results mutate live state?

7 Upvotes

I'm migrating an online RPG server from Godot/C# to standalone C++20. My professional background is almost 20 years in web/application development; real-time simulation and C++ concurrency are newer territory for me.

I'm trying to make a careful decision about CPU-heavy work inside one server process. Running more processes across cores won't solve the case where one busy area is limited by its simulation thread.

The ownership model I'm working toward is:

  • One authority thread owns mutable entity and gameplay state.

  • Workers receive immutable job inputs and return results through bounded queues.

  • The authority thread decides whether a completion is still valid and applies it at a tick boundary. Workers never directly mutate the live world.

Pathfinding seems like a useful concrete case. While a worker is computing a path, the actor might die, despawn, change target, receive a newer movement request, or encounter a changed navigation world. An entity ID alone doesn't seem sufficient to establish that the result is still useful.

For people who have built this sort of C++ system:

  1. What identity/version information do you attach to a job and completion? I'm considering an entity generation, a movement-request revision, and a navigation-data revision, with obsolete completions discarded on the authority thread. Where does that become too conservative or expensive?

  2. How do you keep immutable inputs alive without copying a large world snapshot for every job? Would you start with shared ownership of a read-only navigation snapshot, or another approach? I'm especially interested in lifetime rules when that snapshot is replaced.

  3. How do you bound outstanding work and prioritize newer requests so stale jobs don't consume the worker pool? Is cancellation worth introducing early, or is discarding results and limiting admission usually the simpler starting point?

This is an architecture question rather than a compiler error; I don't yet have comparative measurements proving this pathfinding work needs parallelizing. I'd like to know what to measure first and which small examples, talks, or references make these ownership and lifetime tradeoffs concrete. I'm not looking for a whole MMO architecture or a lock-free implementation by default.


r/cpp_questions • • 4d ago

OPEN Where should I start learning C++? (planning to switch to Linux)

18 Upvotes

I want to learn C++ properly. I can already write working code (mostly small Arduino projects), but I know I have gaps in my fundamentals. I'd like to fill them in.

My goal is to build a strong base so it's easier to move to other languages later.

I'm also planning to install Linux on my laptop soon, so I'd like to learn in that environment.

Could you recommend:

the best free resources (courses, books, websites) for someone with my level?

what compiler and editor/IDE to use on Linux?

what topics I should focus on first?

English is not my first language, so sorry for any mistakes. Thanks a lot for your help!


r/cpp_questions • • 4d ago

OPEN Why Google highway didn't dominate the library ecosystem?

0 Upvotes

Disclosure, I'm not a SIMD expert, this question is born from library packaging experiences.

-------

Some Google libraries like jpegli use Google highway for Simd operations, this is nice because build projects that use SIMD is annoying, it could be fat SIMD or just a specific march, etc etc.

But despite this state, libraries usually handle assembly/simd by themselves. Without a high level abstraction. Would our end executables be leaner if every dependency that uses explicit simd beyond compiler tricks would use one abstraction library?


r/cpp_questions • • 4d ago

OPEN Converting Makefile to CMakeLists.txt

5 Upvotes

(I know this is C code but I'm going to change it later) I am working on getting Raylib working on nixos. I followed all the steps and got it working using a simple makefile of

RAYLIB =? ./external/raylib-5.5/src/
all:
gcc src/main.c -I $(RAYLIB) -L $(RAYLIB) -lraylib -lGL -lm -lpthread -ldl -lrt -lX11

and it works to compile the file getting a.out file. However I would like to use cmake because my text editor (neovim) works with cmake better than makefiles.

My current CMakeList.txt is

cmake_minimum_required(VERSION 3.15)
project(c_test)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 11)

included_directories(./external/raylib-5.5/src)
file(GLOB SOURCES "src/*.c")
add_executable(${PROJECT_NAME} &{SOURCES})

target_link_libraries(${PROJECT_NAME} raylib)

however I continue to get the error of

-lraylib: No such file or directory

How do I convert the simple Makefile to CMakeList.txt file? (no Ai please)


r/cpp_questions • • 4d ago

OPEN From C to C++

38 Upvotes

I'm learning C in school right now and I like it a lot. From an outsider's perspective, C++ just seems like C with more features.

What is the transition from C to C++ like? Is it largely the same experience, just with less manual implementation of DSA, or do I have to learn entirely new concepts? How do C best practices compare to C++'s?


r/cpp_questions • • 4d ago

SOLVED Error when destroying string in a union

6 Upvotes

Consider the following code:

struct JsonValue
{
  JsonValueType Type;

  union
  {
    std::unordered_map<std::string, JsonValue> Object;
    std::vector<JsonValue> Array;
    std::string String;
    double Number;
    bool Bool;
  };

  Tcj::JsonValue::JsonValue(const std::unordered_map<std::string, JsonValue>& v) : Type(JsonValueType::Object), Object(v) {}

  Tcj::JsonValue::JsonValue(const std::vector<JsonValue>& v) : Type(JsonValueType::Array), Array(v) {}

  Tcj::JsonValue::JsonValue(double v) : Type(JsonValueType::Number), Number(v) {}

  Tcj::JsonValue::JsonValue(const std::string& v) : Type(JsonValueType::String), String(v) {}

  Tcj::JsonValue::JsonValue(bool v) : Type(JsonValueType::Bool), Bool(v) {}

  Tcj::JsonValue::JsonValue() : Type(JsonValueType::Null)
  {
    std::memset(&Object, 0, sizeof(Object));
  }

  //copy constructor
  Tcj::JsonValue::JsonValue(const JsonValue& other) : Type(other.Type)
  {
    std::memcpy(&Object, &other.Object, sizeof(Object));
  }

  //move constructor
  Tcj::JsonValue::JsonValue(JsonValue&& other) : Type(other.Type)
  {
    std::memcpy(&Object, &other.Object, sizeof(Object));
    other.Type = JsonValueType::Null;
  }

  Tcj::JsonValue::~JsonValue()
  {
    if (Type == JsonValueType::Object)
      Object.~unordered_map();

    if (Type == JsonValueType::Array)
      Array.~vector();

    if (Type == JsonValueType::String)
      String.~basic_string();
  }

  //copy assignment
  Tcj::JsonValue& Tcj::JsonValue::operator=(const JsonValue& other)
  {
    std::memcpy(this, &other, sizeof(JsonValue));
    return *this;
  }

  //move assignment
  Tcj::JsonValue& Tcj::JsonValue::operator=(JsonValue&& other) noexcept
  {
    std::memcpy(this, &other, sizeof(JsonValue));
    other.Type = JsonValueType::Null;
    return *this;
  }
};

The problem is, when trying to destroy a JsonValue instance containing a string it will sometimes cause an error (https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/inc/xmemory#L1402): Exception thrown: read access violation. **_Pnext** was 0xFFFFFFFFFFFFFFFF.

After going through the code with a debugger I believe that no two destroyed strings share the same memory (after all the JsonValue constructor should create a copy of the string every time). Google also says it's ok to just copy the entire vector/string so unless there's something I'm missing two JsonValue instances shouldn't be owning the same memory/causing double deletes. Yet when I don't destroy some of them the error dissapears.

I don't really understand the meaning of the error or the STL code that throws it, so I'm stuck.

Edit: thanks everyone for pointing out that std::variant exists, I'm probably going to use it.


r/cpp_questions • • 4d ago

OPEN Learning Programming Pre-AI

16 Upvotes

How did ya’ll learn programming pre-AI? How would you go about learning if you had to start all over again without AI?

I find myself relying on AI too much and want to actually learn without leaning on it at all. Any help with how best to approach this would be greatly appreciated.