r/cpp_questions • u/yuvayikici • 3h ago
OPEN How to master? What courses to watch?
How can i write my own network stack? How can i code using linux syscalls and header. Idk what to do. Please help me im so confused. I got the basics of cpp btw
r/cpp_questions • u/yuvayikici • 3h ago
How can i write my own network stack? How can i code using linux syscalls and header. Idk what to do. Please help me im so confused. I got the basics of cpp btw
r/cpp_questions • u/DasKatzenbrot • 4h ago
Hello, I have been using c++ for the last few months and I am pretty satisfied with it and I think that it is going to be and stay as my main language. I have looked at the alternatives like C#, GDScript, Rust etc. and want to get into game developement. My current issue is that i can't seem to find a good engine/framework. I tried Godot with GDExtension, but the implementation for c++ was quite tedious and not integrated - Unreal Engine is a bit too much functionality for me, as I only want to do simple games. Engines like Flax oder O3DE seem to unknown, so I am currently thinking about using a framework wich fullfills the tasks of an engine, like rendering, physics etc. I have used raylib and sfml before and managed to get a small architecture to run(mostly through a small render class, very limited in functionality). If anyone had similar issues finding something to work with c++, please do tell me your suggestion for what I could use
r/cpp_questions • u/drofosfera • 8h ago
Good day,
I am an intermediate game developer coming from Unity, and I'd like to deepen my knowledge of game development. Let me tell you about myself first and how I got here.
Over the summer I've learnt a considerable amount. I've learnt about OOP. I can realize design patterns, refactor code according to SOLID principles, and write systems which are clean and scalable. I've come to realize that objects, such as classes and interfaces, aren't just magic words I put into the IDE. They're actual abstract objects which have their own properties and relationships between one another (I'm still in high school so I don't really know any comp sci theory other than what I use to create games). In June I've created a game featuring an AI which uses a complex Hierarchical State Machine governed my emotional dynamics and external events. My implementation of the State machine pattern allowed me to use it all over the game without issue or extra modifications.
I've also learnt about Data-Oriented Design. Over July I've gotten the feel for Unity's Data-Oriented Technology Stack. I've learnt to think in terms of ECS, be cognizant of the memory I'm using, and parallelize code. I've written an N-Body simulation which uses the Barnes-Hut algorithm. Coupled with multi-threading (Jobs) and the Burst compiler, the sim can handle ~100K bodies with collision at a presentable framerate.
In August I've joined a team to participate in the National Technological Olympiad in Russia to go to uni, so I know what "readable" code means, how to use version control and how to write professional, clean and beautiful code. However, that's besides the point.
As I've matured as a programmer, I learnt about the concept of low-level game development. I've come to realize that Unity isn't a magic box. Previously, I didn't even consider that there's something under the hood of the game engine. I just wrote code, clicked buttons, and it all just worked. However with time, I've come to realize that this isn't the case. Unity is yet another program which hides a considerable amount from me. I realized this mainly in July, when I needed to know how the CPU worked more-or-less (when things like cache lines and race conditions became important). Then I realized that I really am at the very tip of this metaphorical iceberg of programming, looking down at the deep water below.
Here's when I've learnt about C++. I know that this language is often regarded as the foundation of just about everything, including games. I've used it briefly before. Long ago, I've written a little Pong project with C++ and built it with CMake, having used SFML to render objects to the window. I've also used C++ to solve simple Codeforces problems, so I do have the rudimentary knowledge of input/output on C++. But that's about it. My aim is to use the language to learn about low-level game development, to "break free" from the game engine and expand the domain of my expertise (maybe to even write my own game engine in the future). I can learn the API of the language rather quickly (e.g. how to write lambdas, how to import libraries, anything I can already do in C#), however I know that's not all that I'll need.
I am aware of the gaps in my skills. I have the high-level knowledge, just not the low-level knowledge. Even though I know how to use DOTS to write parallelized, Data-Oriented systems, I can't really tell you how to resolve even a simple race condition, or what a memory leak actually looks like, or how the CPU and RAM are laid out, or how things actually work on the low level. Even though I can use the API Unity and C# provide to use OOP to write clean and modular code, I don't really know how a class actually works, what differentiates data types from reference types (other than "something, something, pointers, something, something"), and how things actually look like inside memory. Unity hid all those troubles from me. So I know that these gaps must be addressed for me to proceed in my learning journey. I learn fast though (as I've shown), so it's not that big of a deal.
Here's where I need your help. I know that to learn efficiently I first need a plan, a roadmap per se. Given my experience, how should I approach learning low-level gamedev on C++? What stuff do I need to learn about? And in what order? What is your advice?
I'd love to hear from you wonderful people.
r/cpp_questions • u/Shevvv • 10h ago
I have these three lines inside my constructor. I'm using C++23, configured through CMake. IntelliSense complains because SubCursor is non-copyable and non-movable:
function BooksReport::Group::Cursor::Cursor(BooksReport::Group::Cursor &&) cannot be referenced. It is a deleted function
If I understand correctly, copy elision should bypass copying in these examples:
using SubCursor = BooksReport::Group::Cursor;
subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->uniform.getCursor())));
subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->nonUniform.getCursor())));
subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->singles.getCursor())));
This implementation is due to the fact that SubCursor registers its address within the parent Group object upon creation. Normally a SubCursor is created during loop initialization and thus corresponds to an object on the stack. In this specific case I need objects stored in a list, hence my attempt to put them on a heap and store unique_ptr for easy memory management.
Like I said, the compiler is completely fine with this, but IntelliSense isn't. I hate red squiggly lines. Does anyone know if this can be solved?
r/cpp_questions • u/Beginning_Book_2382 • 14h ago
I am a freshly minted C++ Qt developer in that I just completed an online course for C++ and the basics of the Qt framework within the past few days.
I am looking for video tutorials on how to build a GUI application using the Qt framework using Qt Quick and QML. For reference, I am not completely new to programming. I am a full-stack mobile and web developer who has been developing both types of applications for years. My tech stack in React (Next.js)/React Native on the front-end and pure Django or Django REST Framework + Django Channels on the backend.
What originally got me into web development was Corey Schafer's Django tutorial series which guided me through developing a web application using Django assuming I already knew HTML, CSS, and Python. That is when I learned that I learn best with YouTube video series I can follow along while the instructor explains what I'm coding. Is there any such series for Qt Quick and QML like building a notepad app? YouTube search results only turn up outdated tutorial series using Qt Widgets which IS NOT what I'm using and am avoiding because I want to construct the UI using QML files, not the widget picker.
Thanks in advance for your help!
r/cpp_questions • u/Expert_Sheepherder24 • 19h ago
Hi, C++26 added "template for" operator , https://cppreference.com/cpp/language/template_for .
GCC 16.2 it supported. It works with std::tuple, std::array, but can't compile with std::span<T,N> fixed size.
How to achieve that, std::span<T,N> also worked with "template for" ?
https://godbolt.org/z/6s9MfzTeb
It be very useful for hand-by unroll loop.
I try specialize std::tuple_size, std::tuple_element, std::get for std::span<T,N> , but it don't helped.
r/cpp_questions • u/xeriax51 • 1d ago
Our professor showed us this topic today but i can't Say ive understood It very well.
From the few examples he showed us, It felt like Just adding extra steps to a function rather than creating those straightfowardly.
When its a time id actually use those rather than not ? To prevent errors of some kind ?
r/cpp_questions • u/Slow_Negotiation_935 • 1d ago
I’ve working with C++23 and I’m making some constructors/methods constexpr and seeing improvements in performance. So far so good. The problem is I don’t want to apply it ‘everywhere’. Is there a good source of advice , or anyone got any good tips?
r/cpp_questions • u/No-Locksmith-7719 • 1d ago
What path to take when parsing large files (on Linux Debian server, the KVM flavour)? Will std::fstream in binary mode do or do we have to look into APIs?
Apart from the performance, the app is memory sensitive, so where to store those read chunks while in a loop? Would a simple char[something] buffer do?
Finally, we would like to avoid those nasty reinterpret_cast<char*> constructs while reading, but are wondering if those are actually used in production? I should also add that the file sizes vary greatly.
r/cpp_questions • u/asukalangleyfanlol • 1d ago
Please help i have been searching for like a week now. And i cannot make a decent looking ui for my life.
r/cpp_questions • u/Seagull78Reddit • 1d ago
Hello, I just started learning about threading and learned that if you don't join or detach a thread, it will kill your program. Looking at the following code,
void my_func() {
for (int i = 0; i < 100; ++i) {
std::cout << i << ' ';
}
std::cout << std::endl;
}
int main() {
std::thread{ my_func }; // A
std::thread{ my_func }.join(); // B
std::thread{ my_func }.detach(); // C
}
A does in fact kill the program. However, when I run this, I only get the output for my_func() once, and that output prints before A causes termination. I also only get the output for my_func() once when A is commented out.
Am I not seeing the output for C because the program just ends immediately after, so C doesn't have time to print anything out? What happens if I detach a thread and end the program before it finishes?
I did not compile with flags. I threw this in Visual Studio (non code) because it's convenient.
r/cpp_questions • u/Educational_Big_8856 • 2d ago
I am a student in high school in second year.I want to learn c++ autodidact
r/cpp_questions • u/Blayer98 • 2d ago
Hi there, so I’ve been trying to patch out a piece of code in The Sims Legacy Collection that disables the -debug_objects command line from being enabled, but both MinHook and CMake are giving me such a hard time that idk what else to do or where to ask… There are no tutorials AT ALL for compiling MinHook with MinGW-W64-gcc, only for Visual Studio (not Code!) which I can’t use because I’m on Arch Linux…
If anyone could advise me please I’d really appreciate it…
r/cpp_questions • u/buddyisaredditer • 2d ago
Hey everyone,
I've been working on SeaChess, a chess application with its own chess engine, and I'd appreciate it if some of you could take a look at the code and give me an honest review.
I'm currently trying to improve my C++ skills and prepare for a C++ developer job. I'd love to hear your thoughts on a few things:
What could I improve in terms of code quality, design, and overall implementation?
Is this a good project to include on my resume when applying for C++ developer roles?
What other projects, skills, or topics should I focus on to improve my chances of getting a C++ job?
I'm open to constructive criticism and would appreciate any advice, especially from people who work professionally with C++.
GitHub: https://github.com/TejasKayande/SeaChess
Thanks!
r/cpp_questions • u/virgin-chocolaty-hoe • 2d ago
hey everyone, i was planning to start the website learncpp.com, the fact is that ik some of the cpp and have coded around 300+ questions in cpp on lc and cf combined, its just that i want to learn everything in detail and sometimes i just keep discovering new things in cpp, whats the most effective way to do it from this website
r/cpp_questions • u/Interesting_Cake5060 • 3d ago
For those of you who saw the word “Rust” in the title, don't be alarmed. I don't want to start yet another holy war about which language is better. I'm here for some design advice.
Recently, I set myself the goal of writing a console-based Internet packet monitor. To my surprise, I found very few C++ projects whose source code I could study. But I did find one project that I liked, and that is https://github.com/matthart1983/netwatch. It’s written in Rust and is quite well-written (I don’t know Rust, but even I was able to understand some parts of the code, this is how I define "well-written").
One part of the code caught my attention more than the others. This part is located in the dpi folder. https://github.com/matthart1983/netwatch/tree/main/src/dpi
Essentially, the main things we have are the following:
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum AppProtocol {
/// DNS query or response — first question's qname + qtype, plus the
/// header RCODE on responses.
Dns {
qname: String,
qtype: u16,
/// Response code from the DNS header (`0`=NOERROR, `3`=NXDOMAIN,
/// …). `Some` only when the QR bit marks this a response; `None`
/// for queries.
#[serde(default)]
rcode: Option<u8>,
},
I might be wrong, but I think it's called ADT (if I'm wrong, please forgive me—I'll correct the title of this post).
Another part is this
pub trait Classifier {
/// `Some(protocol)` when this classifier recognizes the payload,
/// `None` to fall through to the next classifier.
fn classify(&self, payload: &[u8], is_tcp: bool) -> Option<AppProtocol>;
}
And finally, here are the following sections for each of the protocols:
pub struct DnsClassifier;
impl Classifier for DnsClassifier {
fn classify(&self, payload: &[u8], is_tcp: bool) -> Option<AppProtocol> {
if is_tcp {
return None; // DNS-over-TCP exists; skip for now.
}
if payload.len() < HEADER_LEN + 1 + 4 {
return None; // minimum: header + root qname(1) + qtype+qclass(4)
}
let qdcount = u16::from_be_bytes([payload[4], payload[5]]);
if qdcount == 0 {
return None;
}
// Header flags: QR is the high bit of byte 2; RCODE is the low
// nibble of byte 3 (RFC 1035 §4.1.1). We surface the response code
// only on responses (QR=1); queries report `None`.
let is_response = payload[2] & 0x80 != 0;
let rcode = if is_response {
Some(payload[3] & 0x0F)
} else {
None
};
// ... some lines here
My question is this: What would the design of the classes/structures look like if we were writing all of this in C++?
I'm curious to see what elegant, clean code for exactly the same task might look like in C++.
The first thought that came to mind was to simply write a protocol interface that included a `classify` method.
class Protocol {
public:
virtual ~Protocol() = default;
// note: return type of this function is void
// i don't know how to do it better
// maybe std::optional?
virtual void classify(std::span<std::byte> payload, bool is_tcp);
}
Beyond that, we simply have a bunch of derived classes for each protocol.
class DnsProtocol : public Protocol {
public:
constexpr auto HEADER_LEN = 12u;
virtual void classify(std::span<std::byte> payload, bool is_tcp) {
if (is_tcp) return;
if (payload.size() < HEADER_LEN + 1 + 4) {
return; // minimum: header + root qname(1) + qtype+qclass(4)
}
}
}
What do you think?
r/cpp_questions • u/Seagull78Reddit • 3d ago
Hi I am trying to play around with some code and made the following:
class Obj {
public:
Obj() : ptr{} {}
void set(int const& x) {
ptr = &x;
}
int const& get() {
return *ptr;
}
private:
const int* ptr;
};
int main() {
Obj obj;
{
int x = 5;
obj.set(x);
}
std::cout << obj.get() << std::endl; // prints 5
}
This compiles and runs even if I remove the const qualification from ptr, the return of get(), and the parameter for set(). Does it not abort or throw an exception if I access a dangling reference or pointer?
Update: thanks everyone!
r/cpp_questions • u/bhul_chuk_maaf17 • 3d ago
Hi all, can you please recommend me some resources that you have followed for compile time programming in modern C++ for eg: constexpr, consteval or template metaprogramming.
Is there some consolidated resource for the same ?
r/cpp_questions • u/OtherwisePatience135 • 3d ago
r/cpp_questions • u/Copronymus09 • 4d ago
Progress there is so incredibly slow, they don't even have full C++23 coverage at trunk and we are at the end 2026, so that's what? a 4 year old gap. Don't companies want better qol?
r/cpp_questions • u/Entire-Comment8241 • 4d ago
I coded this p2p client application with librats and now I want to test it with googletest but after running ctest into the build directory I got this exception:
Test project /home/andrew/x86/win32/p2pClient/build
No tests were found!!!
My cMakeLists.txt:
cmake_minimum_required(
VERSION
3.14)
project(p2pClient)
# GoogleTest requires at least C++17
set(
CMAKE_CXX_STANDARD
17)
set(
CMAKE_CXX_STANDARD_REQUIRED
ON)
include(FetchContent)
enable_testing()
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)cmake_minimum_required(VERSION 3.14)
project(p2pClient)
# GoogleTest requires at least C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
enable_testing()
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
and this is the result after running cmake -S . -B build:
cmake -S . -B build
-- The C compiler identification is GNU 16.2.0
-- The CXX compiler identification is GNU 16.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at /usr/share/cmake-4.3/Modules/FetchContent.cmake:1386 (message):
The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
not set. The policy's OLD behavior will be used. When using a URL
download, the timestamps of extracted files should preferably be that of
the time of extraction, otherwise code that depends on the extracted
contents might not be rebuilt if the URL changes. The OLD behavior
preserves the timestamps from the archive instead, but this is usually not
what you want. Update your project to the NEW behavior or specify the
DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
robustness issue.
Call Stack (most recent call first):
CMakeLists.txt:10 (FetchContent_Declare)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/andrew/x86/win32/p2pClient/build
r/cpp_questions • u/amagi77 • 4d ago
Nice to meet you. It’s been 10 years since I first started working with C++, but since I haven’t been able to land a job, my experience is limited to hobby projects. How can I write good code?
I suppose, unlike code written for work, hobby code is only meant to be understandable to the person who wrote it. How is that different from professional work?
I enjoy using libraries like raylib, dxlib, and SDL3.
I’d like to learn the techniques for preventing code from becoming a “spaghetti mess” in a professional setting.
I’ve looked up a lot of this on Gemini, but I’d like to hear some human opinions.
Translated with DeepL.com (free version)
r/cpp_questions • u/No-Locksmith-7719 • 4d ago
Which (fairly simple) C++framework would you recommend for a simple http server that binds to a hard-coded port and does a simple listen, read, write shebang on a server? We don't need nothing fancy or complex, we just want to avoid that native Linux sockets APIs boilerplate coding.
r/cpp_questions • u/IndividualSituation8 • 4d ago
Lets say I have async code or some sort of timer or scheduler that calls a lambda later on some event, how do i test this in simple way in existing frameworks?
Is using futures or other sync mechanism the only way? or a simpler runloop/eventloop style facilities exist in test frameworks to simplify things?
For now looks like the test itself has to take on more theeading/orchestration/synchronization responsibilities.
For event driven and interactive apps, async execution would be common.
r/cpp_questions • u/Many_Difficulty_490 • 5d ago
AI rn isnt the best at c++ and although you cant hope that it stays bad forever but i was wondering if the job market was gonna be ok in the future for c++
i wanna keep learning graphics programming and hope it might get me a job one day
sorry if this post sounds dumb, idk what to do with my life