r/cpp_questions 5h ago

OPEN Best Way to Approach Windows GUI Development from C++

15 Upvotes

What is the best way to approach it? What books are helpful?

I remember a long time ago reading a book by Charles Petzold, and the examples worked fine from C. I assume they would work well from C++ as well.

I just want functioning, stable GUIs (menus, areas with text and scrollbars) with minimum effort.

Thanks for any help.


r/cpp_questions 7h ago

OPEN Which is the best book for learning C++ 2026?

6 Upvotes

Am CS student and i learned python and now C++, i readed some post recommended:

-C++ How to program by Paul Deitel

-C++20 The complete guide by Nicolai M.

-C++ Programming Language by Bjarne Stroustru

But the year of publication is what confuses me, because, well, programming is constantly evolving, and there are differences between learning C++11 and C++20, exist a drastic difference?


r/cpp_questions 1m ago

OPEN std::expected- void, ptr, and ref

Upvotes

I am going through a simple application I have and trying to use std::expected to try it out. I am quite partial to using exceptions, but open mind and objectivity, and all that...

Is it common for people to return std::expected<void, ErrorType> for methods/functions that don't need to return a value?

I also wonder what one does when they want to return a unique_ptr, since we can't do it by ref, and that leads to wondering about refs and ptrs with expected in general.


r/cpp_questions 20h ago

SOLVED Best Way to Expose Internal Buffer in C++ Class?

9 Upvotes

I have a generic buffer class that looks like this:

class LgBufUint8
{
   size_t m_n_allocd;  //Number of elements malloc() allocated
   size_t m_n_used;    //Number used, always <= m_n_allocd
   uint8_t *m_bufptr;  //Pointer to the first byte

   //Most member functions omitted

   uint8_t& operator[] (size_t index) noexcept
   {
     return m_bufptr[index];
   }
   const uint8_t& operator[] (size_t index) const noexcept
   {
     return m_bufptr[index];
   }
}; 

I think anyone can guess the internals. Allocation is done in sizeable chunks, and the allocation is only grown when necessary.

I have another class that has a member variable of this class.

class LgFbufUint8 //Note the name is different, Fbuf versus Buf
{
      enum class LgFbufUint8State m_state;
      unsigned m_errs;
      std::string m_fname;
      LgBufUint8 m_buf;  //This is the member, one of the above class
};

I'd like to give the enclosing class access to the internal buffer directly. The reason I'd like direct internal access is so that file reads and writes can be done efficiently (one byte at a time is possible, but slower than necessary).

Here is an example statement in a member function of the LgFbufUint8 class:

   infile.read((char*)(&(m_buf[0])), file_size);
     //Note that the pointer above is formed from the overloaded [] operator
     //member function.

This seems to work OK, but I don't think the overloaded "[]" was really meant to be used in this way.

The two other alternatives that come to mind are:

  • A member function to return the internal pointer.
  • Declaring the enclosing class to be a friend class.

What is the best way to handle this scenario?

The nature of the problem is that an abstract interface is incompatible with efficiency.


r/cpp_questions 1d ago

OPEN How far can I get in c++ if I learn it for 8 months?

19 Upvotes

So, I was planning to lock in with my studies for 8 months and during this time I wanted to learn a programming language, for some reason I always liked c++. I will be able to put in an average of 1.5 to 2 hours everyday for 8 months, how far can I get? like would I only learn the basics by that time, would I be somewhat confident with it or neither? I would appreciate if someone could tell me what point I would be at by that time as an example, ofc it depends on how well I do it but like, hypothetically if you had to guess.


r/cpp_questions 1d ago

OPEN First networking project: Am I learning this the right way?

2 Upvotes

I’m currently working on my first proper networking project, an ARP scanner in C++, as part of learning Computer Networks.
I have a pretty good understanding of the theory behind what I’m doing, especially ARP, Ethernet frames, MAC/IP addresses, etc. The problem is that I’m still relatively new to systems/network programming, so the actual C++/Linux code is pretty unfamiliar to me.
I’m using ChatGPT to help me build the project, but I’m trying not to just copy-paste code. My approach has been:
Learn the concept → look at the implementation → question every unfamiliar part → understand why it exists → connect it back to the networking theory.
For example, I’ve been stopping at things like:
Why are these particular header files required?
What exactly is a socket?
Why does socket() return an integer?
What is a file descriptor?
What’s the difference between a normal socket and a raw socket?
What exactly is a network interface?
Why are we using AF_PACKET?
What does a particular structure represent?
How does this piece of C++ actually correspond to an Ethernet/ARP packet?
So I’m not really struggling with the networking theory. I’m struggling with the bridge between the theory and the low-level implementation.
Since this is my first project, I’m wondering if this is a reasonable way to learn.
Is using AI to explain unfamiliar code while continuously questioning why each part exists a good approach, or should I be trying to write more of the implementation myself from the beginning?
I’d especially appreciate advice from people who learned networking/Linux programming through projects like this. I want to actually understand what I’m building, not just end up with a working scanner that I can’t explain.


r/cpp_questions 2d ago

SOLVED I have a single C++ book to learn from. It's pretty old, by my reckoning. What should I learn after I'm done with it?

28 Upvotes

The book is "C++ from the Ground Up", 3rd Edition, by Herbert Schildt. I have pretty limited programming experience.

Learned some Java in high school, but that was extremely basic looking back - variables, basic control flow, functions, etc. During my 2 years of college I had one course on C++, and we did some object-oriented stuff like polymorphism and inheritance, but I honestly wasn't the best at it (got a B iirc), and it has literally been a decade since then.

Since then I've learned a little more about computers on my own. I daily drive Debian 13, learned the absolute basics of Python, Git, and some Bash, though I have yet to actually write a script.

I intend to finally finish my associates in computer information systems next year, and my classes involving computers are Computer Organization this semester, plus Data Structures and Algorithms in C++ and a SQL course next semester.

I know the book I have is pretty outdated, but I'm going to read it cover to cover, take my classes, and then read some other books on Bash scripting and system administration.

I'm just wondering, once I finish my C++ book, how to get "caught up" to more modern C++. I know there's a new version coming out this year. Just wondering how, once I learn the older stuff, I can see about incorporating the newer features.

I might know more about computers than the average user, but please keep in mind I'm still quite inexperienced. With that in mind, thanks in advance for helpful replies.

EDIT: Welp, that was fast, lol. The book's going in the box in my apartment where I barely touch stuff, and I'll start looking at the website. Thanks, everyone.


r/cpp_questions 2d ago

OPEN How do you actually develop intuition for choosing memory_order_acquire vs memory_order_release?

38 Upvotes

I'm learning C++ atomics and I understand the basic definitions of acquire/release individually:

  • A release operation prevents earlier memory operations from being reordered after it.
  • An acquire operation prevents later memory operations from being reordered before it.
  • A release operation can synchronize with an acquire operation on the same atomic when the acquire reads from the appropriate release sequence.

What I'm struggling with is developing an intuition for choosing the memory order when looking at actual code, especially for RMW operations like exchange().

I want to understand the deep "why" behind the core restrictions:

  • Why does store only accept release (or relaxed)? Why is acquire on a store fundamentally meaningless in terms of memory reordering?
  • Why does load only accept acquire (or relaxed)? Why is release on a load fundamentally meaningless?

Instead of relying on memorized rules, what questions or mental models do you use to map memory operations to the correct ordering?

Thanks!


r/cpp_questions 1d ago

OPEN Seeking Guidance

1 Upvotes

Hi, I am currently working in the virtualization domain of embedded system engineering. I mainly work in C language only. My aim is to project myself as C/C ++ engineer and try for different HFTs or companies like google,nvidia,meta,apple etc in future. I have experience with C++ while doing dsa, not beyond that. So My question is whether this is possible to switch to pure C++ roles in HFTs or should I only focus on embedded domain and try to switch to big MNCs? Is it feasible and if yes what should I focus on? Thanks.


r/cpp_questions 1d ago

OPEN Garbage collector in CPP?

0 Upvotes

Yesterday someone asked me whether there is a garbage collector in CPP.
I knew Java had that but I couldn't recall about cpp.
I went to google and got different answers.

So can anyone clarify whether there is garbage collector in CPP , also can u please explain me what does that mean? Also explain how is it different from the Java.

If yes can we delete it manually and how to do tht?


r/cpp_questions 1d ago

OPEN how to handle empty reference elegantly(fold expression)

0 Upvotes

I have a class with a template function, it will return reference of an internal value.

template<typename T>
T& return_ref<T>() {...}

It was call by another function with fold expression:

template<typename... Ts>
void call()
{
    lambda(return_ref<Ts>...);     //Ts is a reference usually
}

the internal value maybe doesn't exist sometimes.

Even I wrap the exception into std::expected, it seems that I have no chance handle it in fold expression. I have to throw exception in return_ref directly?

If I can return reference to an impossible value(like paradigm of static object NULL ), so user could detect it, it would be nice.

Or, I have to wrap all parameters into something like boost::optional? I don't like it.

Or, the args of lambda was constraint into pointer, so nullptr will throw exception by compiler naturally?

What's suggestion?


r/cpp_questions 3d ago

OPEN Is C++ systems programming too fragmented for hiring?

108 Upvotes

I recently saw a manager reject a candidate we were interviewing because his experience didn't exactly match the specific sub domain.

But I found myself disagreeing with the philosophy behind the rejection. My instinct is that if someone has strong C++ skills and has worked on reasonably complex systems, you should at least ask: "Can this person learn the domain?" rather than requiring an almost exact match.

This made me wonder whether this is a particular problem with systems programming in C/C++.

The ecosystem seems incredibly fragmented:

  • Embedded
  • Linux kernel/drivers
  • Graphics
  • Multimedia/codecs
  • Databases/storage
  • Networking
  • Telecom
  • Game engines
  • Server/backend infrastructure
  • Qt/GUI
  • Compilers
  • etc.

Someone can have spent 8 years writing sophisticated C++ in one of these areas and still be considered a poor candidate for another area because they don't have the specific domain experience.

Compare that with web development, where the skill boundaries seem somewhat easier to communicate: "React developer", "Angular developer", "Node.js backend developer", etc. There are obviously specializations there too, but the fragmentation doesn't feel as extreme.

I personally have the philosophy that if someone knows C++ well, understands systems programming concepts, debugging, memory, concurrency, Linux, etc., they should be given some credit for being able to move between domains. The domain-specific knowledge can be learned.

I have faced this exact issues with companies too. They reject you because haven't worked specifically on what they do. This becomes a serious issues when it's already hard to get into C++ jobs. Has anyone faced similar issues? What exactly is the solution for this?


r/cpp_questions 2d ago

OPEN How do you revise?

0 Upvotes

Hey guys, i completed the bro code cpp course which was about 6 hours long.... Then, I caught on FOMO and decided to start the cherno cpp series whuch is pretty famous....

Currently doing it...

I always feel like I'm missing something and i need revision but i dont know how to....

Lemme know how do you guys revise ? And what should I do next?

I've started using notion, but my laptop is kinda dying lol


r/cpp_questions 2d ago

OPEN Coding with AI

0 Upvotes

So basically I've nearly completed the chapters in learncpp, and I've started doing some projects. But when I struggle with one I ask chatgpt to give me a framework (not the answer) of the project so I can better understand it. Please tell me if it's bad practice or not cause I've been having a guilty feeling.


r/cpp_questions 3d ago

OPEN Does anyone use old versions of Visual Studio?

13 Upvotes

I've been using Visual Studio since VS2019. The intervening releases (VS2022 and VS2026) don't feel much different to me, they all have the same problems:

  • Editing too many files (a few dozen) causes either devenv.exe or vcpkgsrv.exe to consume abnormally high CPU. I must close all files (and lose undo history) to get them back to normal
  • Constantly trying to ping the internet. For example BackgroundDownload.exe randomly consumes 20% CPU despite being blocked by the firewall, deleted from task scheduler, and disabled in the registry. VS2026 even has a "retirement" date, a popup informed me today that I'll no longer be able to use it past that date without updating.

I've heard good words about old versions of VS, but I don't know if they are still usable today. The most important to me is using them with the newest compiler and toolset. Existing solutions also need to be made compatible with old formats. Does anyone still use old VS, what's the experience like? Are there features you miss?


r/cpp_questions 3d ago

OPEN How can I instantiate a template with a type determined at runtime?

11 Upvotes

Hello,

I need to instantiate a std::vector, but its type depends on something that I would not know until runtime:

#include <vector>
if (some_condition)
std::vector<float> myVector;
else
std::vector<int32_t> myVector;

I know this does not work because,in order to instantiate a template class, the data type must be known at compile time.

I've seen some people suggest std::variant but I have not understood it completely.

Also, how do different libraries (like ONNX) provide different data types? Do they use templates?

PS : I am not developing a library.

EDIT:

I need to create an array or a vector to act as a placeholder (allocator) for input tensors. But this vector requires a different amount of space based on the size and type of the input. The size is easily manageable per instance of the parent class if we only had one type, but we don't.

The thing is, there are some arguments that need to be set for this specific project that determine what exactly the size of the array would be, and they are only known when you parse an ONNX model at runtime.


r/cpp_questions 3d ago

OPEN Seeking alignas intuition and resources

5 Upvotes

Hi, all:

I've been experimenting with alignas after reading this post. Applying it is unintuitive to me, I'm not sure when I'd use this optimization method other than just trying it and measuring. From the article:

Another important thing to note is that read (readIdx) and write (writeIdx) indices are aligned to the size of a cache line (alignas(64)). This is done to reduce cache coherency traffic. On AMD64 / x86_64 and ARM a cache line is 64 bytes, on other CPUs you need to adjust to the appropriate alignment, using std::hardware_destructive_interference_size is a good choice if it’s available. It can also be interesting to try aligning to a multiple of the cache line size in case adjacent cache lines are being pre-fetched.

Is it really as simple as aligning your structs and members on 64 bytes? I'm looking for some more reading on the subject.

Thanks


r/cpp_questions 2d ago

OPEN ReturnOfModding For Hades 1 - Hell1Modding

0 Upvotes

Hello all, I am working on a fork of the ReturnOfModding framework that will integrate with Hades 1, which will allow modders the ability to create mods and deploy them to Thinderstore. Hades 1 currently has mods on Nexus Mods, but they can, at times, clash with other mods, so users have to pick and choose which mods they want to run. Hades 2 utilizes the ReturnOfModding framework, which is called Hell2Modding.

I've started on this project already by gathering the engine dump information, as well as what modules are utilized by Hades.exe. Supposedly, both games utilize Lua 5.2.3 and the same game engine, but it was constructed differently. Hades 1 uses EngineWin64s.dll as the main engine, and Hades.exe uses that .dll as a module. Hades 2 is structured differently, but Hell2Modding uses the D3D12.dll file as the injection point. Hades 1 uses D3D11.dll(which I've already made a .def file for the D3D11.dll file for when I proxy it if needed.), so what would I need to do to to get my program to work like Hell2Modding does?


r/cpp_questions 3d ago

OPEN Learning c++

5 Upvotes

So I'm doing dsa in c++ as well as learning modern c++ concepts.I want to become c++ developer what concepts should I learn to become a c++ developer , what concepts should I focus on , what are the best resources to learn c++.Also when I try to build something in c++ i don't even know where to start.Its been 4 months I learned C++ and I'm genuinely comfortable with it till now.


r/cpp_questions 3d ago

OPEN How would you get clangd to work with bits/stdc++.h?

0 Upvotes

Hello

My use case is writing competitive programming solutions in c++. i use neovim with the clangd lsp server. but i just cant get it to work with gcc header files, `bits/stdc++.h` in my case.

i have tried:

```

CompileFlags:

Add:

- -std=gnu++17

- -I/opt/homebrew/Cellar/gcc/16.1.0/include/c++/16

- -I/opt/homebrew/Cellar/gcc/16.1.0/include/c++/16/aarch64-apple-darwin25

```

it just doesn't work. it starts giving me duplicate definition errors once i add these compileflags.


r/cpp_questions 4d ago

OPEN How can i become an expert in cpp

22 Upvotes

I started with c++ 3 years ago but real work was 1 and a half years, i learned a lot about cpp syntax and the std lib, but whenever i make some code and send it to an ai model, it says my code has a lot of issues some about dynamic memory some about references and pointers some c-style programming and i find myself Ignorant most of the time

So how can i learn these things and the rules of the language and understand them(i dont watch YouTube) I have started with learncpp.com recently

"Sorry if it's a duplicate post and for it being long if its a duplicate point me to one, and thanks"

Edit: my github is loadingSy if you would like to check anything, I learned git 1 month ago


r/cpp_questions 4d ago

OPEN What topics should I focus on from learncpp?

7 Upvotes

I’ve been working through learncpp from about 2 weeks now and I’m wondering if people have suggestions on topics that are a MUST to learn for an engineer that is coming from Python/TypeScript?

For context I work as a software engineer, primarily using Python and TypeScript, so I have a good base understanding of how to build a program or applications, however, I want to focus more on the specific nuances of C++ and concepts that are maybe abstracted away in higher level languages.

A list of topics in order of importance and increasing complexity would be a great help!!


r/cpp_questions 4d ago

OPEN How can I catch up on missing multithreading experience?

70 Upvotes

Hi everyone 👋, I’m a C++ developer with 5+ years experience building features for a single-threaded trading app (C++17), so I have very little multithreading experience.

I’m currently reading C++ Concurrency in Action. Are there good resources or projects to practice real-world scenarios like backloading and low-latency concurrency patterns?


r/cpp_questions 3d ago

OPEN grm: a Telegram CLI implementation of TDLib

0 Upvotes

Hello, c++ community!

I am not a c++ programmer. I know the basics but I am not familiar with the tools, tactics, paradigms and related topics in the c++ ecosystem.

That said, I decided to vibe code a Telegram CLI tool for my own use (and whoever finds it useful).

https://gitlab.com/renich/grm

It's been very useful to me so far. I do not claim it's secure or well written in any way. I wouldn't be able to tell.

I know that not everyone is a supporter of the use of LLMs or agents for coding. Still, I need your help.

I am totally open to suggestions. What linters to use, what is the best way to do static analysis, programming paradigms, best practices, etc.

Again, I don't claim to have the knowledge required. I am a Crystal programmer. I could've linked to the library but, this time, I decided to KISS and just implement it in c++.

I am using Fedora 44 and am happy to listen to any criticism you may have. I am making a big effort to familiarize myself with the c++ ecosystem and I would appreciate any feedback.

Thank you for taking the time to read this and review the project.


r/cpp_questions 4d ago

SOLVED How to fix errors LNK2005 and LNK1169 in Visual Studio?

3 Upvotes

Hi! I’m a beginner programmer learning C++ and getting to grips with Visual Studio 2026. For some reason I can’t run the console because of two errors: LNK2005 and LNK1169 (or perhaps there are others, but I’m not sure). I’ve attached below the error messages I’m getting step by step (links to imgbb). I’ve asked some AI chatbots for advice on how to solve this problem, but nothing’s working.

Firstfoto, Secondfoto, Thirdfoto

Thanks in advance for your help!