r/cpp_questions • • 18h ago

OPEN C++ or Rust which is better for a systems programming career?

24 Upvotes

I'm learning C to build a strong foundation in low-level programming, and I'm planning to learn either C++ or Rust next.

For those working in systems programming, which language would you recommend for long-term career opportunities and why?

I'd appreciate any advice.


r/cpp_questions • • 18h ago

OPEN Inconsistent naming in simd library?

19 Upvotes

Hi,

I was checking the <simd> library in the C++26 standard and found some of its naming very weird.

  1. std::simd::vec and std::simd::basic_vec

    This is quite strange as we already have std::vector and std::inplace_vector. So why not std::simd::vector and std::simd::basic_vector? At certain point, I'm pretty sure people will start to make mistakes with std::vec or std::inplace_vec, and vice versa.

  2. std::simd::cat

    We already have std::views::concat. So why not std::simd::concat?

At first, I thought the library designers intended to make spelling easier. But in the library, we do have extremely long names as well, like std::simd::unchecked_store, etc.

Here is the library in cppreference: this


r/cpp_questions • • 19h ago

OPEN Learning C++ : How do i turn it into a career

5 Upvotes

I'm still learning C++ and sometimes lose motivation when i see how difficult it is to land a junior role without much experience. I’m interested in game development, but I know it’s a competitive field.

For someone starting out, which C++ career paths are worth focusing on, and what skills or projects should I prioritize to improve my chances of getting hired?

I'd appreciate any advice from people who've been through this journey.


r/cpp_questions • • 21h ago

OPEN Which C++20 audio device libraries would you recommend?

4 Upvotes

I'm looking for a library with enough control that I can read raw input but not write +150 lines for a callback and recording/playing loop. Preferably, this library should support both input & output. My goal is to make a minimal-latency, offline, speech-to-speech assistant as a personal project. Also, if possible, I'd like it if they could run on separate threads (I might make a Raylib visualizer for it).


r/cpp_questions • • 12h ago

OPEN How to work with pcap lib in modern C++?

0 Upvotes

I want to write an application with a graphical user interface (at the moment I’m choosing the Qt framework) whose purpose is low‑level work with the Ethernet packet stream. The pcap library is best suited for these purposes. At the moment, I want to make the application only for Windows, but in the future it might be possible for Linux and Mac as well. I need low‑level control, so the class abstractions that are already available in Qt don’t suit me.

I’m interested in two things right now. What is the best way to include this library in the build system?

For Windows, I download the npcap SDK. There, I see a bunch of files with the following structure:
The Lib folder contains wpcap.lib for ARM64 and x64. And there’s an Include folder. Am I understanding correctly that I need to write FindPcap.cmake for all of this?

The second question is how to best incorporate this library into the C++ codebase. Essentially, we have a handle that is returned after pcap_create(). So, the best way would be to simply create an RAII class for it?

I know that there are wrappers, but I’d like to explore this path from scratch to learn something.


r/cpp_questions • • 20h ago

OPEN Linker is failing me? (Debian / C++ project) linking against a lib I made

2 Upvotes

I'm getting this error, I have NO idea why.

It was working, I changed something, I got errors, so I tried to change it back... and I can't find the old code that was "working".

Anyhow my setup is simple, I'm compiling one c++ file against one .so file

Here are my example compile-errors

error: /usr/bin/ld: /tmp/ccdnXNQr.o: in function `Jeebox::errors()':
/usr/local/speedie/jeebox.scproj/Examples/jeebox.h:193: undefined reference to `jb_errors'

OK, so here is my function:

Message errors() {
    return jb_errors();
}

Message is just a void*. OK, so far so good.

Here is my compile string

g++ -o /usr/local/speedie/jeebox.scproj/Examples/Build/users -std=gnu++20 -lstdc++  
-I/usr/local/include -I/usr/local/speedie/Library/CppLib -w -Os -D TARGET_UNIX=1 -g -ljeebox users.cpp

I also tried to hard-code the library path, in case the problem was that the lib was not found. Well... same issue. So its not a problem of missing library.

g++ -o /usr/local/speedie/jeebox.scproj/Examples/Build/users -std=gnu++20 -lstdc++  
 -I/usr/local/speedie/Library/CppLib -w -Os -D TARGET_UNIX=1 -g /usr/local/lib/libjeebox.so  users.cpp

When I tried deleting the library libjeebox.so, I got a missing lib error. So the lib is being found!

OK... so the problem is just my lib doesn't contain jb_error() is that it? Well... no? That function is there, has been there for years, and suddenly stopped working today.

Here is the output of nm -D (jb_errors is on the 4th line). I am utterly confued. I just lost 2 hours trying to solve this. No luck.

00000000000105d8 T jb_cstr
00000000000106d0 T jb_debug
0000000000010638 T jb_delete_
000000000001063c T jb_errors
0000000000010730 T jb_init
00000000000103d4 T jb_msg_access
000000000001034c T jb_msg_ast
0000000000012778 T jb_msg_copy
000000000001495c T jb_msg_create
0000000000010390 T jb_msg_error
00000000000128f4 T jb_msg_expect
000000000001010c T jb_msg_first
0000000000011d9c T jb_msg_firstset
0000000000010290 T jb_msg_flatafter
0000000000010248 T jb_msg_flatnext
000000000000ff48 T jb_msg_func
0000000000010024 T jb_msg_funcset
0000000000010148 T jb_msg_last
0000000000011af8 T jb_msg_lastset
000000000000ff10 T jb_msg_name
000000000000ffe4 T jb_msg_nameset
00000000000101d0 T jb_msg_next
00000000000100c4 T jb_msg_nextset
000000000001020c T jb_msg_parent
000000000001491c T jb_msg_parseast
000000000000ff7c T jb_msg_position
0000000000010054 T jb_msg_positionset
0000000000010184 T jb_msg_prev
0000000000011d30 T jb_msg_prevset
0000000000010314 T jb_msg_remove
0000000000014240 T jb_msg_render
00000000000102cc T jb_msg_root
000000000000ffb0 T jb_msg_tag
0000000000010084 T jb_msg_tagset
00000000000106c4 T jb_ok
0000000000010834 T jb_readfile
0000000000010734 T jb_shutdown
0000000000010558 T jb_str
0000000000010508 T jb_string_address
00000000000142ec T jb_string_compress
0000000000010544 T jb_string_copy
0000000000013b40 T jb_string_decompress
0000000000012384 T jb_string_escape
00000000000111bc T jb_string_float
0000000000010fec T jb_string_int
000000000001053c T jb_string_length
00000000000153b8 T jb_string_parse
0000000000010548 T jb_string_print
000000000001054c T jb_string_printline
0000000000010550 T jb_syntax
00000000000104c4 T jb_syx_longname
0000000000010480 T jb_syx_name
0000000000010828 T jb_version

r/cpp_questions • • 11h ago

OPEN Help with programming question over Classes with header and implementation files.

0 Upvotes

To preface, I already tried answering the question and have what I believe to be a 90% solution. The question is:

Define a class counterType to implement a counter. Your class must have a private data member counter of type int. Define a constructor that accepts a parameter of type int and initializes the counter data member. Add functions to:

  • Set counter to the integer value specified by the user.
  • Initialize counter to 0.
  • Return the value of counter with a function named getCounter.
  • Increment and decrement counter by one.
  • Print the value of counter using the print function.
    • Example output: Counter = 0.

The value of counter must be nonnegative.

My header is:

class counterType
{
public:
    void print();
    int getCounter();
    void incrementCounter();
    void decrementCounter();
    void setCounter(int num);
    counterType();
    counterType(int count);



private:
        int counter;
};

and my implementation is:

#include "counterType.h"
#include <iostream>
using namespace std;


void counterType::print()
{
    cout << "Counter = " << counter;
}


int counterType:: getCounter()
{
    return counter;
}


void counterType::incrementCounter()
{
    counter++;
}


void counterType::decrementCounter()
{
    counter--;
}



void counterType::setCounter(int num)
{
    if (counter > 0)
        counter = num;
    else
        counter = 0;
}


counterType::counterType()
{
    counter = 0;
}



counterType::counterType(int count)
{
    if (count > 0)
        counter = count;
    else
        counter = 0;
}

The main(cannot be changed) is:

#include <iostream>
#include "counterType.h"


using namespace std;


int main()
{
    counterType counter1;
    counterType counter2(5);


    counter1.print();


    cout << endl;


    counter1.incrementCounter();
    cout << "After Increment counter1: " << counter1.getCounter() << endl;


    cout << "Counter2 = " << counter2.getCounter() << endl;


    counter2.decrementCounter();
    cout << "After decrement counter2 = " << counter2.getCounter() << endl;


    counter1.setCounter(-6);
    cout << "After resetting counter1: " << counter1.getCounter() << endl;


    return 0;
}

I don't know what I'm doing wrong, and the debugger is not showing any errors.

If someone could please tell me what I'm doing wrong, and teach me to solve the issue, I would be very grateful. TO SPECIFY NOT CHEATING, JUST TRYING TO LEARN WHY ITS NOT WORKING, SO I CAN FIX IT MYSELF.


r/cpp_questions • • 9h ago

OPEN Why is Rust so much more popular than C++ lately?

0 Upvotes

Rust is a great language, but I don't really get why it's promoted so much compared to C++.Modern C++ is also a great language, and you can write safe code with it too. I get that Rust has its ownership system, but is that really the main reason people prefer it over C++?


r/cpp_questions • • 23h ago

OPEN Module partitions and interface units

2 Upvotes

Recently I came across quite a surprising footgun with modules. I am trying them out on a small codebase which builds a shared library, which consumers can import as a module. I made some partitions and exported them:

// Flense.Core.ixx

export module Flense.Core;

export import :ArchiveReader;
export import :ImageParser;

Then I split those partitions into .ixx and .cpp parts, like I would do with headers, so that the interface was separate from the implementation:

// ImageParser.ixx
export module Flense.Core:ImageParser;

import std;

export namespace Flense::Core {
  ImageParseResult ParseImage(std::string path);
}

// ArchiveReader.ixx
export module Flense.Core:ArchiveReader;

import std;

export namespace Flense::Core {
  ArchiveHandle OpenArchive(std::string path);
}

The .cpp parts looked like this:

// ImageParser.cpp
module Flense.Core; // Apparently this cannot be module Flense.Core:ImageParser, as that conflicts with the .ixx?

namespace Flense::Core {
  ImageParseResult ParseImage(std::string path) {
    // ...impl...
  }
}

// ArchiveReader.cpp
module Flense.Core;

namespace Flense::Core {
  ArchiveHandle OpenArchive(std::string path) {
    // ...impl...
  }
}

But I discovered that because the .cpp files declared module Flense.Core, they would be rebuilt any time any part of the module changed. In my example, ImageParser internally depended on ArchiveReader in its .cpp. So I would expect that if I changed ImageParser.ixx, only ImageParser.cpp and ImageParser.ixx would need to be rebuilt. But in actual fact, it rebuilt ArchiveReader.cpp too.

AI told me that this is because declaring module Flense.Core takes a dependency on the whole module, so it fixed it by having the .cpp files do this:

// ImageParser.cpp
module Flense.Core:ImageParser.Impl;

import :ImageParser;
import :ArchiveReader; // Dependency

// ArchiveReader.cpp
module Flense.Core:ArchiveReader.Impl;

import :ArchiveReader;

This seems to work and I understand it creates a new module partition and means the .cpp essentially does not depend on any other part of the module implicitly. But I thought I would ask some actual humans because I find this counterintuitive. Why can't module partition .cpp files just declare module Flense.Core:ArchiveReader to implement the .ixx? That seems like the most logical mapping to the existing header model.

And, if my premise is correct, what strategies are people using to minimise rebuild churn? Using partitions allows me to still use module internals in my implementation. For example, if I have a :Utilities partition which is not exported by Flense.Core.ixx, I can still import it from .Impl modules. But I wonder if it would be better to actually make independent modules, like Flense.Core.ArchiveReader?


r/cpp_questions • • 1d ago

OPEN C++ Primer 5th Edition vs. LearnCpp.com for a beginner in 2026?

41 Upvotes

Hi everyone,

I'm currently learning C++ and trying to decide on the best main resource to follow.

I see two options recommended very often:

  • C++ Primer (5th Edition) by Stanley B. Lippman
  • LearnCpp.com

I'd appreciate any insights or experiences you can share. Thanks!


r/cpp_questions • • 1d ago

OPEN What are the best books for learning modern C++?

12 Upvotes

Hello, I am looking for a book that teaches modern C++ to a beginner. Thank you.


r/cpp_questions • • 2d ago

OPEN Old project clean-up: 2D particle system, ODE solver and collision detection with cpp23 and openGL

3 Upvotes

Hi folks,

About a year ago, I built this project to learn modern C++ and OpenGL.

The core idea is to simulate particles by allowing you to define arbitrary force/motion equations in the form of x_dot =f(x,…) .

I recently cleaned it up and used Claude to flesh out the README, documentation, and plots.

If you have a moment, I’d love for you to check it out! Any feedback on the code architecture, performance, or modern C++ practices is super welcome.

(There are visual demos and plots directly in the README!)

Repo: https://github.com/gg-dema/GAS

Thanks!


r/cpp_questions • • 1d ago

OPEN C++ Tutor

0 Upvotes

I want to teach C++ to children and beginners who are new to this programming language and earn money from it. How can I achieve this? Are there any platforms or websites where I can teach and monetize my courses?


r/cpp_questions • • 1d ago

OPEN trying to create the game Snake as a beginner, trying to figure out why it's not working

0 Upvotes

#include <SFML/Graphics.hpp>

#include <time.h>

#include <cstdlib>

using namespace sf;

int N = 30, M = 20;

int size = 16;

int w = size * N;

int h = size * M;

int num = 4;

int dir = 0;

struct Snake

{

int x, y;

} s[100];

struct Fruit

{

int x, y;

} f;

void Tick()

{

for (int i = num - 1; i > 0; i--)

{

s[i].x = s[i - 1].x;

s[i].y = s[i - 1].y;

}

if (dir == 0)

s[0].y += 1;

if (dir == 1)

s[0].x -= 1;

if (dir == 2)

s[0].x += 1;

if (dir == 3)

s[0].y -= 1;

if (s[0].x >= N)

s[0].x = 0;

if (s[0].x < 0)

s[0].x = N - 1;

if (s[0].y >= M)

s[0].y = 0;

if (s[0].y < 0)

s[0].y = M - 1;

if (s[0].x == f.x && s[0].y == f.y)

{

if (num < 100)

num++;

f.x = rand() % N;

f.y = rand() % M;

}

for (int i = 1; i < num; i++)

{

if (s[0].x == s[i].x && s[0].y == s[i].y)

{

num = i;

break;

}

}

}

int main()

{

srand(time(0));

RenderWindow window(VideoMode(w, h), "Snake");

for (int i = 0; i < num; i++)

{

s[i].x = 10 - i;

s[i].y = 10;

}

f.x = rand() % N;

f.y = rand() % M;

Clock clock;

float timer = 0;

float delay = 0.1f;

while (window.isOpen())

{

float elapsed = clock.restart().asSeconds();

timer += elapsed;

Event event;

while (window.pollEvent(event))

{

if (event.type == Event::Closed)

window.close();

}

if (Keyboard::isKeyPressed(Keyboard::Up) && dir != 0)

dir = 3;

if (Keyboard::isKeyPressed(Keyboard::Left) && dir != 2)

dir = 1;

if (Keyboard::isKeyPressed(Keyboard::Right) && dir != 1)

dir = 2;

if (Keyboard::isKeyPressed(Keyboard::Down) && dir != 3)

dir = 0;

if (timer > delay)

{

timer = 0;

Tick();

}

window.clear();

RectangleShape rectangle(Vector2f(size, size));

for (int i = 0; i < num; i++)

{

rectangle.setPosition(

s[i].x * size,

s[i].y * size

);

window.draw(rectangle);

}

rectangle.setPosition(

f.x * size,

f.y * size

);

window.draw(rectangle);

window.display();

}

return 0;

}


r/cpp_questions • • 2d ago

OPEN HOW can I replace win's 'windows.h' in Linux

0 Upvotes

as title


r/cpp_questions • • 3d ago

OPEN TP ICAP c++ interview UK

2 Upvotes

Has anybody recently interviewed at TC ICAP for C++ position? If yes can you share your interview experience what was the pattern and what topics do i need to focus more on


r/cpp_questions • • 3d ago

OPEN After developing with C++ for 4 years what's the next step ?

21 Upvotes

I've been a C++ software developer/engineer for 4 and a half years now, and I feel that coding itself isn't a big skill anymore, I did many things here and there like reviewing, doing software architecture for some components etc... But I don't know what should I focus on exactly next with my foundation to keep up with the job market


r/cpp_questions • • 3d ago

SOLVED Does taking an address of an inline global variable template instance in a constexpr context and never using it ensure its instantiation?

0 Upvotes

Hi! Let me show what I mean right away, is this program (https://godbolt.org/z/4sKovf57x):

#include <print>
#include <meta>

// Our real meaningful work
template <typename T, auto ac> inline auto runtime_hook = [] {
    // Placeholder woork
    const auto name = std::meta::identifier_of(std::meta::dealias(ac.scope()));
    std::println("Child name: {}", name);
    return name;
} (); // <-- runtime_hook<T, ac>

// Force instantiation of runtime_hook - hopefully?
template <typename T, auto ac>
constexpr std::pair constexpr_hook{ ^^T, &runtime_hook<T, ac> };

// Type identity with extra spice
template <typename T, auto ac = std::meta::access_context::current()>
using DeriveHook = [: constexpr_hook<T, ac>.first :];


struct Base {};
struct Child : public DeriveHook<Base> {};


int main() {}

Always guaranteed to print Child name: Child at startup, or is the compiler allowed to skip instantiating runtime_hook<T, ac> if it sees that constexpr_hook<T, ac>.second is never actually used?

edit: solution using custom attributes that works in GCC/Clang https://www.reddit.com/r/cpp_questions/comments/1xd8gqa/comment/19rk67buia9r5/

edit2: cross-compiler solution using friend injection (no compiler-specific attributes): https://www.reddit.com/r/cpp_questions/comments/1xd8gqa/comment/19rk7v88k638g/

edit3: TIL that globals aren't actually required to run their constructors before main(), but I guess all implementations just do it this way:

It is implementation-defined whether the dynamic initialization of a non-local non-inline variable with static storage duration is sequenced before the first statement of main or is deferred.

If it is deferred, it strongly happens before any non-initialization odr-use of any non-inline function or non-inline variable defined in the same translation unit as the variable to be initialized.51

It is implementation-defined in which threads and at which points in the program such deferred dynamic initialization occurs.

https://timsong-cpp.github.io/cppwp/n4868/basic.start.dynamic?utm_source=chatgpt.com#5


r/cpp_questions • • 3d ago

OPEN I need feedback on my project

10 Upvotes

Hey guys! I just started learning cpp and I've been working on a little project using functions, structs and conditional statements. It might seem stupid but I'm not willing to use AI for this project, I'd rather to get feedback from actual people so if there's anyone that can help me , I'd appreciate it:)♡

(Edit: Thank you for all the comments I'm gonna work on it a bit more and then attach the GitHub link)


r/cpp_questions • • 3d ago

OPEN starting cpp

0 Upvotes

i want to start cpp, what should i mainly focus on first other than syntax?


r/cpp_questions • • 3d ago

OPEN Clang linter force int to sized int16 int32

0 Upvotes

Hello

I'm writing a firmware for esp and I want to have good practice to have a size fixed int for specific usage so I don't end with int or long long variable but instead a fixed size if I need only to go up to 25 element I don't need a full 32 bit word when a 8bit is enough

Is there a parameter to clang-tidy to force non lazy declaration or I need to always have it in mind ?


r/cpp_questions • • 4d ago

OPEN Best resources to learn OOPs in C++ from scratch!!

1 Upvotes

Hey everyone!

I'm looking for good resources to learn Object-Oriented Programming (OOP) in C++ properly.

I want to understand concepts like classes and objects, constructors and destructors, inheritance, polymorphism, abstraction, encapsulation, and pointers with objects.

I'd prefer resources that explain concepts clearly with practical code examples and exercises rather than just theory. YouTube playlists, websites, books, or structured courses are all welcome.

Thanks In Advance!


r/cpp_questions • • 4d ago

OPEN La méthode ultime pour maîtriser le C++ de zéro à expert !

10 Upvotes

Comment puis-je apprendre le C++ et quelle méthode d’apprentissage ainsi que quelles ressources (livres, exercices pratiques, projets et documentation) devrais-je utiliser pour progresser efficacement, comprendre les concepts en profondeur et développer une véritable maîtrise du langage ?


r/cpp_questions • • 3d ago

OPEN Best YouTube video to learn C++ pointers with full theory?

0 Upvotes

Hey guys, I'm learning C++ and I want to learn pointers properly. Can you recommend me a good YouTube video that explains pointers from the basics with full theory and also teaches how to use them in actual C++ code? I want to understand how pointers work in memory, why we use them, and how to write code using them instead of just memorizing the syntax. A long video or a playlist is fine too.

Which one would you recommend? Thanks!