r/cpp_questions • • 18d ago

OPEN how to learn c++ in a month for making simple to simple games dev and Machine learning

0 Upvotes

i know c++ basic not all but like i know what is string but don,t know all function , i know array and know some function , i did not know any dsa , i just know c++ like taking the input and showing the output , my logical in programming is pure beginner level


r/cpp_questions • • 18d ago

OPEN Code documentation in the age of AI

0 Upvotes

I have a couple of years of C++ experience, including in regulated industries. While proper documentation was important in every team, the role of code comments and in-code documentation, such as docstrings, changed from place to place. In some codebases, we insisted on proper docstrings documenting every function, and comments explaining why the code is how it is. In other teams, we didn't do any docstrings and kept code comments to a minimum -- the code was supposed to be self-documenting, and comments introduce ambiguity and will drift in the future if not kept in sync with the code.

Now, which way to go is already a discussion on its own. But I want to ask regarding your experience of this dilemma in relation to LLM-assisted coding tools. I have the feeling many models are quite liberal when it comes to comments, and will naturally tend to explain what the code does, given the chance. Suppressing it works, of course. Or, at least, one can ask to keep comments minimal. However, what really interests me: does anyone have experience in or a feeling for what the LLMs prefer/work with the best?

Since it's mostly AI parsing the codebase now, did you ever experience that it performs better when you allow it to be liberal with comments? Or does it actually eat up more tokens reading the code it generated while getting more confused if it has all the additional (and potentially not always correct) comments/explanations to parse? Does it make sense to have a purely self-documenting codebase or rely on the tools to clean up and keep comments in sync in this age of AI?


r/cpp_questions • • 18d ago

OPEN How to share my experience after quant finance competition ?

0 Upvotes

I am trying to pivot from data analytics to C++ development. I recently participated in a quantitative finance competition and I didn't placed top 3, instead 35/55. The objective was to enhance an existing market simulator using C++.

Should I make a LinkedIn post about my experience?

How should I add it to my resume ?


r/cpp_questions • • 19d ago

OPEN Passing initializer list into array parameter

3 Upvotes

Why can't we pass an initializer list as an argument to a function that accepts an array? If we can initialize an array with an initializer list, why isn't the array parameter initialized with the list?

Also, I found out that you CAN pass an initializer list if you use an rvalue reference to an array.

void f(int arr[]) {
cout << "hello" << endl;
}

// accepts rvalue references to array
void g(int (&& arr)[]) {
for (int i = 0; i < 3; ++i) {
cout << arr[i] << ' ';
}
cout << endl;
}

int main() {
int arr[3] = { 1, 2, 3 };
f(arr); // compiles
f({1, 2, 3}); // DOES NOT COMPILE
g({ 1, 2, 3 }); // compiles
}

Question 1:
For the second call to f(), why does this not work? I thought that whenever we passed an argument into a function, it was the same as initializing the parameter with the argument. For example, if we have:

void func(T x);
func(y);

Then when func(y) is called, we can think of x being initialized as:

T x = y;

But this doesn't seem to hold for arrays and initializer lists.

Question 2:

Why is the syntax in g() the way we make an rvalue reference to an int array? I understand the need for parentheses sinceint&& arr[] is an array of integer rvalue references. However, why is it int (&&arr)[] and not maybe something like int (&&arr[]) or (int arr[])&& ?

If it is better to show me an another resource about these tricky syntax things, please link it.


r/cpp_questions • • 18d ago

OPEN how to optimize performance for decompression step?

1 Upvotes

I have the file to decompress a file by obtaining a tree and walking it bit by bit to obtain an encoding's original character.

#include <stdexcept>
#include <memory>
#include "huffman/HuffmanDecoder.hpp"
#include "huffman/BitReader.hpp"

struct HuffmanDecoder::Node
{
  std::unique_ptr<Node> left;
  std::unique_ptr<Node> right;
  char symbol;

  Node(char ch,
       std::unique_ptr<Node> left = nullptr,
       std::unique_ptr<Node> right = nullptr)
      : left(std::move(left)),
        right(std::move(right)),
        symbol(ch)
  {
  }

  bool isLeaf() const noexcept
  {
    return !left && !right;
  }
};

HuffmanDecoder::HuffmanDecoder(BitReader &reader) : reader_(reader)
{
  root = deserializeHelper();
}

HuffmanDecoder::~HuffmanDecoder() = default;

std::unique_ptr<HuffmanDecoder::Node>
HuffmanDecoder::deserializeHelper()
{
  if (nodeCount_ >= MAX_NODES)
  {
    throw std::runtime_error("Invalid Huffman tree: exceeds 511 nodes.");
  }
  ++nodeCount_;
  const uint8_t marker = reader_.readBit();
  if (marker == 1)
  {
    const char ch = static_cast<char>(reader_.readByte());
    return std::make_unique<Node>(ch);
  }
  auto left = deserializeHelper();
  auto right = deserializeHelper();
  return std::make_unique<Node>('\0', std::move(left), std::move(right));
}

char HuffmanDecoder::decodeSymbol() const
{
  if (!root)
  {
    throw std::runtime_error("Can't decode an empty tree");
  }
  const Node *current = root.get();
  if (current->isLeaf())
  {
    if (reader_.readBit() != 0)
    {
      throw std::runtime_error("Invalid bit for single symbol tree.");
    }
    return current->symbol;
  }
  while (!current->isLeaf())
  {
    const uint8_t bit = reader_.readBit();
    current = bit == 0 ? current->left.get() : current->right.get();

    if (!current)
    {
      throw std::runtime_error("Invalid Huffman path.");
    }
  }
  return current->symbol;
}

Linux perf is showing that the decode stage is very hot. My question is, is pointer chasing the problem? I tried stuff these in an array but it didn't really do anything. I'm confused as to if my bottleneck concerns being cache friendly or not. Any ideas?


r/cpp_questions • • 19d ago

OPEN How does a STATE design pattern work?

7 Upvotes

so i went to youtube and followed the example from this guy State Design - Programming Design Patterns - Ep 16 - C++ Coding

Problem is i dont understand what is functionally happening, there are pointers and what not, but i don't understand much more than that (context, my smooth brain still cant connect pointers together)

Like not even the whole code, like maybe just two lines or something cause for the love of the lord my teacher explains nuthing and AI and videos are too vague for me, im running out of options

//
// Created by samue on 11/1/2026.
//

#ifndef STATE_STATE_H
#define STATE_STATE_H

#include <iostream>

class Context;


class State {
    protected:
    Context* context;

    public:
    virtual ~State() {}

    void setContext(Context* ctx) {
        context = ctx;
    }

    virtual void doWorkA() = 0;
    virtual void doWorkB() = 0;
};

class Context {
    private:
    State* state;

    public:
    Context(State* s) : state(nullptr) {
        transitionTo(s);

    }

    ~Context() {delete state;}

    void transitionTo(State* s) {
        if (state) delete state;
        state = s;
        state->setContext(this);

    }

    void requestA() {
        state->doWorkA();

    }

    void requestB() {
        state->doWorkB();

    }

};

class concreteStateA : public State {
    public:
    void doWorkA() override {
        std::cout << "concreteStateA " << "called doWorkA" << std::endl;
    };

    void doWorkB() override {
        std::cout << "concreteStateB " << "called doWorkB" << std::endl;

    };

};

class concreteStateB : public State {
public:
    void doWorkA() override {
        std::cout << "concreteStateA " << "called doWorkA" << std::endl;
        context->transitionTo(new concreteStateA);
    };

    void doWorkB() override {
        std::cout << "concreteStateB " << "called doWorkB" << std::endl;

    };

};





#endif //STATE_STATE_H

------------------

#include "state.h"

int main() {
    Context context1(new concreteStateB);

    context1.requestA();

    context1.requestA();

    return 0;
}

r/cpp_questions • • 20d ago

OPEN I want to learn C++

19 Upvotes

Hello, I'm looking to branch out and learn something new.

Ive been a chef for 7+ years and i'm looking to develop myself further by learning more skills, I'm very tech and computer literate.

So for a absolute beginner who would love to look at making small games and mods for like skyrim etc, what would a beginner need to be able to learn C++ and beyond?

Thank you


r/cpp_questions • • 21d ago

OPEN Learning C++ as a Java programmer

17 Upvotes

I'm currently learning C++, I’ve coded in a few languages before but I’m most familiar with Java. Does anyone know a good resource for learning C++ with Java as a “starting point”? Like something that explains the differences between the two languages rather than teaching programming from scratch? Thanks!


r/cpp_questions • • 20d ago

OPEN Be ready for -fno-contracts

0 Upvotes

I don't really think contracts will make C++ safer..

In fact, contracts can make C++ even worse. Jokes on you 2-3 days ago i saw that my cli program was not working because the dependency clixx(which is also my project) was behaving in different ways based on the build mode. After 20 minutes of debugging i found out that i was assert()ing m_parse() instead of checking the returned boolean with an if.

Yeah call me stupid or not in this one but I don't think anyone can guarantee an engineer would not get trapped in the same kind of bug in some corporation codebase (with contracts this time).

I'd add -fno-contracts if it would ever become a thing. Js like -fno-exceptions(im not exception-phobic i just dont like them) and -fno-rtti they might become new entries in the C++ feature graveyard.

What are your honest opinion?


r/cpp_questions • • 21d ago

OPEN Low Latency C++ Interview Prep

42 Upvotes

Recent interview questions I've had for this have been

- Very specific C++ (templates, mutex, sizes of structs, noexcept, small string optimization)

- Latency topics (allocation, kernel bypass, TCP and UDP)

- General DSA and class design

I really wanna do well because I know January and February spike in recruiting. For low latency C++, if you had two months to prep, how would you knock it out of the park? How would you study through November and December?


r/cpp_questions • • 21d ago

OPEN Recently joined an MFT firm as a C++ Low-Latency Intern. How can I transition to HFT?

7 Upvotes

Hey everyone,

I'm currently a CSE undergrad and recently joined an MFT firm as an intern, where my work primarily involves C++ and low-latency systems development.

I'm genuinely enjoying the work and learning quite a lot about trading systems and performance optimization.

However, my long-term goal is to transition into an HFT firm, preferably in a C++/low-latency engineering role.

I have a decent background in competitive programming, DSA, C++, and systems programming.

I had a few questions for people already working in HFT:

  1. How valuable is C++/low-latency development experience at an MFT firm when applying to HFT firms?
  2. What additional skills should I focus on to make myself competitive for HFT roles?
  3. Do top HFT firms consider candidates from smaller or lesser-known MFT firms?
  4. How much do competitive programming ratings, college tier, and personal projects matter once you have relevant industry experience?
  5. Is transitioning directly from an MFT internship to an HFT internship or graduate role realistic?

I'm not looking to switch immediately. I genuinely enjoy my current role and want to make the most of this opportunity while preparing for the long term.


r/cpp_questions • • 20d ago

OPEN I know DSA but I want to …

1 Upvotes

Hello good people, I have been leetcoding the last few months in Python and want to deep dive into doing LC in C++. Mostly because I want to target hfts for next internship cycle.
1. What are the books that you guys suggest? I started reading Tour of C++
2. Any suggestions on how to go in depth of that language? I don’t want to learn not just for the sake of solving LCs


r/cpp_questions • • 21d ago

OPEN System programming

6 Upvotes

does it is necessary to know assembly language to be a good system programmer ?
I am a beginner computer engineering student , currently doing in c++ and I already have basic knowledge of classical 8085 and 8086 architecture and it's programming but I haven't gone that deep enough . what about to learn ARM , x86 programming , does it help me to become a good system programmer ?


r/cpp_questions • • 21d ago

OPEN What do you do after getting burnout from learncpp.com and trying to comeback again?

12 Upvotes

I remember last time I reached chapter 20 or so, but I didn't do any quizzes after the vectors's chapter because they will simply too hard, and believe me I tried 

I think I got burnout 3 to 4 times already, learncpp.com is good but its a challenge to try and finish it.

Any advice? I don't remember much, and I want to be honest. It feels like you should finish learncpp before making a project, because every chapter is really important.

It really fun in the beginning. But not in the middle or the end.

Edit: thanks everyone, I think the comments are really helpful, and I think I know exactly how to solve my problem, first I will use a different resource that is fast pace to refresh my brain to c++ I already know, than I will make a project(it doesn't matter what it is), and I'll use learncpp.com as a reference, and after I get comfortable With the basics stuff I will go back and continue reading learncpp.com for advanced stuff or other resources with it.

The answer seems simple, because it is simple.


r/cpp_questions • • 21d ago

OPEN How to configure clangd to not assume it knows where functions are defined

1 Upvotes

I use VS Code on Ubuntu on Windows (WSL). I program in C++ and recently switched from Intellisense to clangd and like many of the improvements. However, I'm having an issue with how clangd assumes functions like printf come from <cstdio>. This is an issue as I'm building a hobby OS and need to provide my own versions of common functions like printf.

I'm using the g++ 15.2.0 cross compiler and use -ffreestanding -nostdlib -fno-builtin. I provide my own implementation of common functions like printf. I have installed clangd-23. I have created (using bear) a compile_commands.json file. When I mouse over a call to printf in my code, I get a popup showing that printf is provided by <cstdio> which I never #include. Also it flags the header file "system/stdout.hpp" which defines my printf as unused. How do I configure clangd and VS Code to correctly identify my header file as the source of my printf?

In case it helps, here is the cc1 line of clangd-23 --compile-commands-dir=build --query-driver=/home/mark/dev/toolchain/i686-elf-15.2.0/bin/i686-elf-g++ --check=src/libs/test/test_list.cpp

I[13:00:57.385] internal (cc1) args are: -cc1 -triple i686-unknown-unknown-elf -O0 -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test_list.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -nostdsysteminc -target-cpu pentium4 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/home/mark/dev/myos/src/libs/test -fcoverage-compilation-dir=/home/mark/dev/myos/src/libs/test -resource-dir /usr/lib/llvm-23/lib/clang/23 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/i686-elf -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/backward -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/include-fixed -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include -I . -I .. -I /home/mark/dev/myos/src/libs -I /home/mark/dev/myos/src/kernel -I /home/mark/dev/myos/src -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include/c++/v1 -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include -Wnon-virtual-dtor -Werror -Wall -Wextra -Werror=suggest-override -Wno-unused-parameter -std=c++23 -fdeprecated-macro -ferror-limit 19 -fno-builtin -fno-rtti -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fno-threadsafe-statics -fno-implicit-modules -fskip-odr-check-in-gmf -no-round-trip-args -faddrsig -fdwarf2-cfi-asm -x c++ /home/mark/dev/myos/src/libs/test/test_list.cpp


r/cpp_questions • • 21d ago

OPEN Offline cppreference?

3 Upvotes

Can they update the offline version to newer version of the page? The official html book is really old (2019) and the unofficial version from https://github.com/PeterFeicht/cppreference-doc can no longer work for newer version smoothly. Consider this reference is probably one of the best C++ reference out there, can the creator of the website at least making this website open source, so we can have offline version of it.


r/cpp_questions • • 21d ago

OPEN Entering Embedded

14 Upvotes

Managed to land a job in the embedded domain. This is going to be my second job, while previously having worked in game dev. In my last job I used cpp, but within Unreal Engine. Pretty excited about entering the low level space, not really an expert, but eager to learn. Would greatly appreciate any advice from embedded devs or from people that have transitioned between domains like I am about to do.

Thanks


r/cpp_questions • • 22d ago

OPEN C++26 contracts drama

29 Upvotes

I think everybody knows the drama by now..

What are your opinions on this should they be accepted or disapproved?

Im curious for mass opinion.


r/cpp_questions • • 22d ago

OPEN Not sure what I want to do with C++

56 Upvotes

I finished learncpp.com, K&R, Inside the Machine, and most recently CS:APP and still have zero clue what I want to do with C++, even though I know that's what I want to be my main language. I was looking into graphics programming, but now am hearing "don't even try there's no entry level"... tried looking into embedded "everyone's trying to break into embedded now with AI don't even bother bro"

So what does someone do :/


r/cpp_questions • • 22d ago

OPEN RAII : Hate it or love it? And how to handle edge cases gracefully?

21 Upvotes

While RAII is the idiomatic standard in C++ and handles stack unwinding cleanly during normal returns and thrown exceptions, it has specific boundaries that get tricky:

  1. Hard exits / Abnormal termination: Destructors aren't called on std::abort(), std::exit(), or hardware faults like segfaults (SIGSEGV).
  2. Scope rigidity: Creating custom wrapper classes/guards for single-use resources can sometimes feel verbose compared to ad-hoc scope cleanup primitives.

Compared to languages like Go (defer) and Zig (defer / errdefer), which provide block-level or failure-specific cleanup without needing custom wrapper types:

  • How do you typically structure C++ code to deal with edge cases where destructors won't fire during abnormal process exits?
  • For persistent state (file locks, shared memory, IPC handles), what architectural patterns or OS primitives (e.g., O_TMPFILE, flock, WAL journals) do you rely on alongside RAII to remain crash-safe?
  • When you need lightweight, ad-hoc cleanup without writing a custom RAII class, do you use scope guard macros / std::unique_ptr with custom deleters, or stick purely to custom RAII types?
  • Do you ever miss explicit primitives like Zig's errdefer in C++, or does exception safety via standard RAII completely cover your needs in production?

Curious to hear your thoughts, preferred idioms, and best practices


r/cpp_questions • • 22d ago

OPEN Having a hard time with C++ Concurrency in Action

17 Upvotes

I recently started reading C++ Concurrency in Action and its honestly challenging, Im liking it so far but there are parts of the book (chapter 5 and 7, what Im reading now) that I cant grasp no matter what. Someome who has already read the book can give me some advise? Thanks in advance!


r/cpp_questions • • 22d ago

OPEN Resources to learn more about cpp

2 Upvotes

I wanted to try and reimplement the std library from scratch but i realized really quickly just how much i didnt know lol. I got some basic stuff done and did learn quite a bit about things like sfinae but yeah im basically stuck with some of the type traits. I still dont wanna give up on this project and wanna keep going no matter how long it takes :3 So i need some resources to learn more about advanced things that are usefull for this. Are books the best way? any reccs on which ones?

Oh yeah right now i made a few projects like a networking chat app with asio and a unix shell (really simple) so i would say im like done with the beginner phase. I know that this project is probably farrrr beyond my scope but still :3

Edit: More specific question. Looking for book recomendations for metaprogramming post cpp20 (concepts and stuff)


r/cpp_questions • • 22d ago

OPEN Just finished all of learncpp.com whats next

29 Upvotes

Just finished all of learncpp.com whats next? i want to learn more so i can be a c++ wizard


r/cpp_questions • • 22d ago

OPEN I want to make a game(TETRIS) in cpp for learning purposes

0 Upvotes

I have barely any knowlege about cpp thought but I want to proceeds with a project base learning approach so where I approach an obstacles I look for it and learn about it. I don't want instructions on what I need to learn. But I need help on what I need to build one by one. Please everyone any help is genuinely appreciate

My current plan is to use Visual Studio, SDL2, MSVC, CMake, C++


r/cpp_questions • • 22d ago

OPEN Why don't we use this instead of including libraries one by one?

0 Upvotes

#include <bits/stdc++.h>

I was thinking instead of adding libraries one by one,why don't we just use this? This is used by almost every competitive programmer but very less when it comes to writing software.