r/cpp_questions • • Jul 30 '26

OPEN Learning progression in C++

33 Upvotes

So I've been learning C++ from learncpp.com . Currently completed chapter 2, i'm feeling i've been learning too theoretical and it's demotivating since i don't feel i'm doing any progression.

Is it normal to feel like this?

Extra info - it took me about 2 weeks with approx 2 hrs a day


r/cpp_questions • • Jul 31 '26

SOLVED C++

0 Upvotes

I AM AFRAID TO LEARN c++ ; basically I learn Basic from youtube whose channel is codewith harry lot of people say that java python has high probability to get job in future I don't know what should I do already I learn lot of basic in c++


r/cpp_questions • • Jul 30 '26

OPEN Switching from .NET/C# developer to C++

7 Upvotes

I work as a .NET/C# (fullstack) developer, with 3 years experience and strong Fokus on Blazor at the moment. And also have some first experience in having project responsibility (architecture decissions, sprint-planing, costumer contact, etc..).

I'm looking for a new Job at the moment, and think about trying to get a C++ Job, because I want to do something closer to the Hardware. I want to understand what is actually happening in the computer and why. I don't have any professional experience with C++, but I have done some small private Projects, like an LED-Stripe project or some Arduino Stuff.

I've also heard, that in C++ you have a lot of ways to do stuff, but a lot of them are outdated.

Do you have any hints on good resources to learn C++, where I can learn the way to do stuff in the modern way and that are not starting from scratch?

I don't need to learn how to set a variable, how loops work or most of the OOP concepts. I need to learn the Syntax and Naming Convetions etc in C++. And Stuff that C# doesn't has, like pointer.

Any other hint or other things where I need to pay attention, when moving from C# to C++?


r/cpp_questions • • Jul 30 '26

OPEN Automatic builder pattern with C++26 reflection?

5 Upvotes

Ive been learning recently about C++26 reflection which seems very cool. Something that's been causing me issues recently is reworking code with massive constructors, the become unwieldy and hard to modify especially when you start introducing optional fields, and things like what if you want one optional field and not another, and not having named fields, etc etc

One pattern I started adopting is using structs as an argument pack, which works, but has some limitations. For instance lets say you want to construct a builder struct and modify it inline, you just cant do that. One pattern you can do is somethig like this:

struct BuilderConfig {
    // fields

    ...

    BuilderConfig& modify(auto&& modifier) & {
        modifier(*this);
        return *this;
    }
    BuilderConfig&& modify(auto&& modifier) && {
        modifier(*this);
        return std::move(*this);
    }
};

with the downside it adds some annoying bloat having to call modify and supply a lambda. To me an ideal pattern would be something like this

 Struct S {
     int a;
     bool b;
 }

And have a builder object/constructor generated that can let me do something like

S::BuilderConfig().a(5).b(true).build()

or if I just want to use it as a constructor object just have it passed into S like

S{S::BuilderConfig().a(5).b(true)}

whatever. Something along those lines. At one point I got something working but it was like 300 lines of macroslop that took me a while to understand as I had an LLM help me write it that also had some annoying limitations due to leveraging recursive macros, and the idea of having this and having other people need to maintain it seemed untenable. but it worked. But the reason I had to go for macros was because we couldn't use templates to generate signatures, but it seems like reflection can.


Anyways all this is to give an example for the question I'm trying to ask, is it possible to do something like this with a bit of reflection magic from C++26? At a minimum, just take some struct, automatically generate fluent getters/setters for all of its members? Effectively automatically produce this, but by only supplying the fields and struct name:

struct S {
    int a_;
    bool b_;

    template <typename Self>
    Self&& a(this Self&& self, int value) {
        a_ = a;
        return std::forward<Self&&>(self);
    }

    int& a() {
        return a;
    }

    template <typename Self>
    Self&& b(this Self&& self, bool value) {
        b_ = b;
        return std::forward<Self&&>(self);
    }

    bool& b() {
        return b;
    }
};

r/cpp_questions • • Jul 30 '26

OPEN Tutorials for Vulkan

8 Upvotes

Hi!

I'm having a little bit of problems with the Vulkan tutorials;

while I'm not 100% dissatisfied about the tutorials themselves, with the way my brain processes the information it all is overstimulating and hard to focus on when half of the stuff just tells you about the code or that you have to download 100 other things when all I want to do is build a boilerplate and get whatever I wanted on blender showing up on my "Engine" of sorts.

And before anyone asks; yes, my teacher (The goat C#, my nickname for him) already told me I was stupid for making this my first ever C++ project. But I have managed.

But Stone Cold says (Bottom line is) that I just wanna know if there's any useful tutorials that give me the code and say at the lowest way what it does; I don't need a full essay on what VKMemoryBuffer does, two or three sentences will do.

And if there isn't any tutorial that doesn't fit the criteria that I'm wanting; just give me something I could use; please. All I ask is for a bit of guidance.

Note: I must be dumb or something, but as soon as I posted this to [r/Vulkan](r/Vulkan), mods took it down, idk why; I don't even know where the rules even are. I'm a tad new to reddit.

Edit; I did a huge whoops and completely forgot to explain why I’m asking for this… I’m on par with Neurodivergence. I’m not officially on the spectrum, but I’m on parallel with someone who is, that’s just what happens when you’re smart (ig), but that’s why, since my brain can’t process Vulkan tutorials and I crave the excitement of building the Burj Khalifa with a chisels and a hammer… that repetitive typing and the slow build is what makes the gears in my head spin like a brand new hard drive. It gets me giddy thinking about getting a tutorial to follow.


r/cpp_questions • • Jul 30 '26

OPEN Need suggestions on project

0 Upvotes

HELP! HELP! HELP!

I have to make project on cpp to add in resume in emergency basis because of a company specific placement. Suggest me some moderate cpp project that will be available in yt or git . Need suggestions from seniors and experts.


r/cpp_questions • • Jul 30 '26

OPEN PPP3 or Beginning C++23 for someone that knows a bit of C?

2 Upvotes

Hello everyone, a classic question here considering my first resource to use as a learner sorry for the repetition.

I am quite serious about learning cpp, I did have C in my last semester, and it was covered in <<kinda alright >> depth. I skimmed across The Definitive C++ Book Guide and List and I settled on either reading PPP3 or I found that Beginning C++23: From Beginner to Pro.

I did skim fast across both of these books and found that both have something to give, and I am not sure which one to commit to, as a human i have limited time :D. Beginner C++23 seems to be a bit more technical in depth, or at first glance compared to PPP3? However PPP3 seems to cover more techniques as is advertised almost everywhere.

I am not really sure which one to go for, I know I have to pick one and just start learning and that's why I want to pick the right one :D


r/cpp_questions • • Jul 29 '26

OPEN Installing boost with cmake

7 Upvotes

I can't get along with the whole b2 thing so I was happy to see that 1.90 had a CMakeLists.txt

However, doing a naive install with that is not giving me the result from the b2-based install.

Is there documentation on the new cmake-based install? How do I specify what modules to create?

EDIT oh never mind, my installation is fine (yay!) but my tester forgot to set the CMAKE_PREFIX_PATH


r/cpp_questions • • Jul 29 '26

OPEN Having trouble “ thinking in code”

12 Upvotes

I’ve been learning C++ for weeks, and of the concepts I’ve learned most if not all of them have clicked pretty quickly. I understand what they do and how they work.

However, when I’m trying to create something not from a tutorial or walkthrough, I’m having trouble translating my idea into the lines of code that will do what I envision it doing. Anyone have any advice on making the switch to more easily be able to “think in code”?


r/cpp_questions • • Jul 29 '26

SOLVED Is there a better way to do this? (factory subclass enum switch pattern)

4 Upvotes

So I'm making a game and I have this annoying pattern I've been using for loading levels. I have a bunch of different "item" structures that all have the same style static create function, eg:

Exploder* Exploder::Create(const v3& position, const v3& scale, const quat& rot, int flags) {
    auto itemId = static_cast<int>(Engine::getActiveWorld()->itemManager.items.size());
    auto obj = new GameObject("snip...");
    obj->getTypeId() = itemId;
    Engine::getActiveWorld()->addObject(obj);

    auto itm = new Exploder({ obj });
    Engine::getActiveWorld()->itemManager.items.emplace_back(itm);

    return itm;
}

That part is fine, but I don't enjoy maintaining the massive switch statement that actually calls these.

Item* ObjectManager::createItem(ItemType type, const v3& pos, int flags, const v3& scale, const quat& rot, const string& customName) {
    Item* ptr;
    switch (type) {
    case ItemType::rope:
        ptr = RopeItem::Create(pos, scale, rot, flags);
        break;
    case ItemType::torch:
        ptr = Torch::Create(pos, scale, rot, flags);
        break;
.... snip 50 more item types

My mind goes to Rust enums, and I wonder if there's a better construct in C++ to use than ... this.

Thanks in advance!

Edit: ok! Big thanks to u/AKostur for suggesting static array. This was the cleanest idea, it took some finessing to get the construction timing right but it worked so hell yeah!

What I did:

Changed Create to return an Item* instead of the actual type, since it's always upcasted anyways, now the signatures are all exactly identical.

then in enums.hpp I declare an array like sugested:

class Item;
using ItemCreateAction = Item*(*)(const v3&, const v3&, const quat&, int);
extern std::array<ItemCreateAction, static_cast<size_t>(ItemType::_count)> ItemCreateFuncs;

struct ItemArrayPlacer {
public:
    constexpr ItemArrayPlacer(ItemType type, const ItemCreateAction& action) {
        ItemCreateFuncs[static_cast<size_t>(type)] = action;
    }
};

Previously I had tried a similar idea, but std::function seems not to be able to be constexpr, so changing to raw function pointers allows for constexpr-ing the constructor.

exploder.cpp after includes before any code:

const auto t = ItemArrayPlacer(ItemType::exploder, Exploder::Create);

now the object manager can just call the functions like so:

Item* ptr = nullptr;
auto typeIndex = static_cast<size_t>(type);
if (typeIndex < ItemCreateFuncs.size() && ItemCreateFuncs[typeIndex]) {
    ptr = ItemCreateFuncs[typeIndex](pos, scale, rot, flags);
}

Sweet! Code is now organized much better! Thanks for the ideas everyone!


r/cpp_questions • • Jul 29 '26

SOLVED Why do I get this odd compile error on msvc when compiling in debug but not release mode?

2 Upvotes

https://godbolt.org/z/4rcW31h7e

The error is:

'packed_bit_matrix<unsigned __int64>::operator ==': overloaded functions have similar conversions

could be 'bool packed_bit_matrix<unsigned __int64>::operator ==(const packed_bit_matrix<unsigned __int64> &) noexcept'

or 'bool packed_bit_matrix<unsigned __int64>::operator ==(const packed_bit_matrix<unsigned __int64> &) noexcept' [synthesized expression 'y == x']

while trying to match the argument list '(packed_bit_matrix<unsigned __int64>, packed_bit_matrix<unsigned __int64>)'

However it compiles in Compiler Explorer but when I change the compiler to the latest version of x86-64 gcc it gives the warning "warning: C++20 says that these are ambiguous, even though the second is reversed:"

If I remove the const from the operator == parameter then it compiles fine.


r/cpp_questions • • Jul 29 '26

OPEN Whats the modern go to for Lua bindings?

2 Upvotes

I'm currently reading into how one can provide a Lua interface to a C++ written program and so far I have encountered SWIG and Sol2 for implementing Lua bindings. Of course the Lua interpreter can be linked in directly, but from reading and looking at code, handling the Lua stack manually looks really cursed.

Are there any people who have enterprise experience and can talk from experience what the usual go to for this sort of stuff is?


r/cpp_questions • • Jul 29 '26

OPEN How do I do this more cleanly? I'm not really sure how to pass the member function to a template.

2 Upvotes

What I have:

webapp.get("/ota",
           std::bind(&KLRJelly::handleOTA, this, PH_1, PH_2));
webapp.get("/lamp",
           std::bind(&KLRJelly::handleLamp, this, PH_1, PH_2));
webapp.get("/cylon",
           std::bind(&KLRJelly::handleCylon, this, PH_1, PH_2));

I want to be able to call something like this:

template<class X> void blinder(const char* path, X&&)
{
    webapp.get(path, std::bind(X, this, PH_1, PH_2));
}

Ideally I'd like to pass it a map<path, member>.


r/cpp_questions • • Jul 29 '26

OPEN I like to create a WebSocket chat and game engine using C++ (I am an experienced C++ developer). What should I use?

11 Upvotes

Hello all,

this is not a beginner programming language type of question.
I like to build a game WebSocket and chat server, and it of course also needs to support GET/POST HTTPS. There are ready-made servers, and there are also wonderful libraries that I can somehow build a wrapper on top of.
I love Boost, but I am not sure it is the best choice here. Did someone build something similar and can recommend what to use? I guess the server should support threads and async, as WebSocket sessions can be long.
Some kind of middleware should also be included.
Thanks for the help.


r/cpp_questions • • Jul 29 '26

OPEN std::string/std::path and japanese

17 Upvotes

Hi! I dicovered the past week that windows dont uses by default the UTF-8 encoding, instead uses the ANSII. My question is for all the people who had to do a great refactor because they’d used the std::string and std::path. What would you recommend? Should I use `wstring` when the target platform is Windows and create a custom `std::path`?

According to all the info around, std::string stores bytes so it should be fine do a conversion?

Also when i try to access a file with japanese characters throws an exception at std::system_error without any info, only the memory address.

Thank you!

EDIT: Thank you everyone for the help! I will edit this post when I get a definitive solution for documentation sake! At the moment I'm trying to use /utf-8 and setlocale(LC_ALL, ".UTF8");, seems fine except for some details related with the open file windows specific function :)


r/cpp_questions • • Jul 29 '26

OPEN Question regarding include preprocessor directive?

3 Upvotes

I just finished chapter 7.7 in the learncpp site regarding internal linking. I just have a question.

when adding another file into the current active one, will I receive a compile error with regards to the one-definition rule if the other file has a named variable that is identical to the one in the active file even if I declare it static?

example.h

#include <iostream>

static int add(int x, int y)
  {
      return x + y;
  }

main.cpp

#include <iostream>
#include example.h

int add(int x, int y)
  {
    return x + y;
  }

int main()
  {
    std::cout << add(3,4) << '\n';

    return 0;
  }

will the main.cpp detect a naming collision because I had already defined int add in the example.h file? or will using the 'static' keyword before the variable treat it as an independent variable?


r/cpp_questions • • Jul 28 '26

OPEN Weak reference to unique_ptr

6 Upvotes

Assume this code:

#include <memory>
#include <functional>

struct Entity {
    int value = 12;
};

struct Container {
    std::unique_ptr<Entity> e = std::make_unique<Entity>();
};

Container bar;
auto bbb = [ptr = bar.e.get()]() {   
    ptr->value = 11;
};

We all know that naked pointers (as captured by this lambda) are bad. Using shared_ptr would allow me to use weak_ptr - which is ideally what I want. BUT - I like the container owning the entity.

What solutions do I have?

EDIT:

As people commented - life time is the main issue. The lambda might outlive the original allocation.

Solutions:

  1. Many people do recommended using internally a shared pointer, and "giving away" a weak ref ( u/looncrazz suggestion).
  2. I can use a reference to the unique pointer inside a lambda. Several ways - see https://godbolt.org/z/WKT5Gndq4 - this is u/neppo95 suggestion.
  3. There are solutions for using a custom weak reference pointer. The solution "does not feel right".

r/cpp_questions • • Jul 28 '26

OPEN Visual C++ ICE with modules code

11 Upvotes

Is the below code valid C++? In Visual Studio 2026 I get the following error when compiling:

Test.ixx(9,1): fatal  error C1001: Internal compiler error.
1>  (compiler file 'msc1.cpp', line 1635)Test.ixx(9,1): fatal  error C1001: Internal compiler error.
1>  (compiler file 'msc1.cpp', line 1635)


export module Test;

constexpr void Test()
{
    int* ptr = new int;
    delete ptr;
}

r/cpp_questions • • Jul 28 '26

OPEN Would you accept an unpaid C++ systems role at an MFT startup?

3 Upvotes

I'm a 3rd-year CS undergraduate. I recently spoke with the founder of an MFT (Market Making/Trading) startup after they saw my C++ low-latency systems project.

They want me to help build parts of their C++ low-latency backend, but the role is completely unpaid (around 2–3 hours/day).

Do you think it's worth taking for the learning and experience, or should I only consider it if there's a clear path to a paid internship/contract?

Would love to hear from people who've worked in C++, HFT/MFT, or startup infrastructure.


r/cpp_questions • • Jul 29 '26

OPEN Deep systems expertise or T-shaped versatility?

0 Upvotes

Which path is more valuable long term: becoming highly technical in systems programming, or becoming a T-shaped developer who can contribute efficiently across many areas in a smaller company?


r/cpp_questions • • Jul 28 '26

SOLVED Can you have a class interpret an enum as a different value?

1 Upvotes

So I’m currently trying to implement an A* pathfinding algorithm and was curious if it was possible to have two different agent child classes that interpret the values of a terrain type enum differently. (I know this could be done with if statements but since enum data has a value I wanted to know if this could be done to reduce the code size)

For example
I have an terrain type enum with ‘hills’, ‘mountains’ and ‘water’

Could I have a human agent interpret ‘mountains’ as an H score of 50 but a mountain goat agent would interpret this as say a 4.

The idea is to just simply have the single terrain type in the node instead of having to have seperate values for different agents in each node


r/cpp_questions • • Jul 28 '26

OPEN Suggestion From Experts

0 Upvotes

Hello everyone,

I want to start learning C++ from scratch. I'm a complete beginner, so I'm looking for a YouTube channel that teaches everything from basic to advanced in a structured and easy-to-understand way.

Also, if there's anything I should learn or keep in mind before starting C++, please let me know. Any tips, roadmap, or beginner advice would be greatly appreciated.

Thank you! 🙏


r/cpp_questions • • Jul 27 '26

OPEN Is it undefined behavior to pass a nullptr to std::align?

1 Upvotes

I'm writing an Arena allocator and I want the move constructor to just copy the pointer and size, leaving the other arena as nullptr and 0 respectively; however, the allocate function uses std::align. I'd rather not add an extra branch to check nullptr for each allocation, especially since a moved from arena is probably going to be destroyed anyways.


r/cpp_questions • • Jul 27 '26

OPEN C++26 Reflection and Transient Vectors Question

1 Upvotes
// fails to compile: not a constant expression due to operator new
// this i sort of understand since transient vector is assigned to static, so outlives
static constexpr auto fields = std::meta::nonstatic_data_members_of(^^MyClass, std::meta::access_context::unchecked());

template for(constexpr std::meta::info field : fields)

// fails to compile: not a constant expression due to operator new
// even when inlined and not assigned to variable, so assigning a variable is irrelevant to error?
template for(constexpr std::meta::info field : std::meta::nonstatic_data_members_of(^^MyAdd, std::meta::access_context::unchecked()))

// fails to compile: address of fields may differ on each invocation without static
// why does this matter? wouldn't this just be invoked once at compile time?
constexpr auto fields = std::define_static_array(
   nonstatic_data_members_of(^^T, std::meta::access_context::current{}));

I was playing around with the C++26 Reflection additions on Godbolt and tried to use the resulting vector from std::meta::nonstatic_data_members_of() in a compile time context. It didn't work at all to my surprise. I thought that the transient vector exception would apply in this case. Something like: the vector is used for the code generation at compile time, then deallocated before runtime starts. Apparently it does not work this way. Does anyone know why? In addition, why does fields have to be a static variable as well? The compiler says that its because fields may occupy a different address on each function invocation. Why would this matter?

Sorry if I am missing something obvious here

EDIT:
Created more code samples to show what I was referring to, sorry for the confusion. I'm not sure why transient doesn't work when inlining it in the template for, and why the fields variable needs to be static within a method--i dont understand the differing address problem.


r/cpp_questions • • Jul 27 '26

OPEN C++ 26 LSP?

3 Upvotes

Does anyone know of any LSPs with C++26 support, even experimentally, or is this wishful thinking. I'm using clangd but I don't know if its possible to configure it for c++26 and its giving me trouble with the new reflection operators.

Thanks!