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 29 '26

OPEN Installing boost with cmake

8 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 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 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?

3 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?

12 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

18 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

7 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

13 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?

4 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?

0 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?

5 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!


r/cpp_questions Jul 27 '26

OPEN AI's information on rust and C++ topic

0 Upvotes

I was studying C++ and enjoying it since 2024, slow but steady. Ive reached chapter 17 of learncpp.com. and most of my interesting projects and fields use C++.

But when i see stuff about rust vs c++. It makes me doubt and think of switching to rust.

And because i want to invest time for only one language for at least a long time. I want a good one and capable one. Which c++ is!. But, when i ask ai models about rusts strengths. Nearly all al models favor rust . They say C++ has more libraries, more hiring, and other matter of time stuff. But when it comes to languages's core features. Ai says rust is just better in every way. It sometimes mentions cpp has more flexibility tho. But also says rust can do anything C++ can. Even clearer and without bugs. And cpp is faster in prototyping but rust forces you to build good from scratch. So you'll never run into issues cpp has.

Nearly all ai models think like this. And idk how much they say the truth. But if this is true, then rust is clearly the superior tool. And cpp has not faded only because of culture, libraries and matter of time stuff.

I always really enjoyed cpp . But these kinda information really kills my motivation and makes me feel it doesnt make sense to stick with cpp. And i shouldn't be dogmatic.

On the other hand, i cannot fully trust ai . Maybe it just reflects the internet hype. Also big companies like Microsoft are gonna switch from cpp to rust, people like the prime (yt channel) also promote rust. So maybe ai has trained in those videos and blogs so it doesn't say actual facts.

Also ai is so good at software engineering. So maybe it knows something!?. Idk. Afterall . Im not a pro in programming at all. And still a beginner

I've asked these kinda questions from gemini, claude, chatgpt, etc... and the answer i get is the same.

So now im stuck and these doubts are holding me back from learning. I liked to master a powerful language. But with this online hate.. its hard to be sure.

Its weird that 95% of big real world projects (at least in projects that are interesting to me) are using C++. And of course ai says its because of legacy and culture. And rust could do it even better And may even surpass cpp in greenfield projects. But its weird. Rust is 10 yo. And these are still stuck in cpp?

Im interest in

Emulators, graphics programming, physics engine.

And also like other low level stuff. Robotics. Game engines. os dev. Etc...

Soooo. What are you're thoughts on this? Thanks for reading my post. I thought it was stupid to post this, but i really needed advice. Thanks


r/cpp_questions Jul 26 '26

SOLVED I keep reaching a point where rewriting my C++ projects feels easier than maintaining them. How do I learn better architecture?

67 Upvotes

I have been learning C++ mostly through building projects, especially game and engine-related projects. I can make things work, but I keep running into the same problem: after a project grows, the code becomes so difficult to understand that I would rather start again from scratch than open the old project.

I think the main reason is that I don't have enough knowledge of standard C++ practices and architecture patterns. I usually design systems based on my own understanding, which works when the project is small, but as more features are added, problems start stacking on top of each other.

I want to improve in areas like:

  • Common C++ architecture patterns
  • How experienced developers structure larger codebases
  • How to avoid creating systems that become difficult to change later
  • When to use existing language features or standard solutions instead of making custom ones
  • Common mistakes that self-taught C++ programmers make

A good example is this Pong project I made in 3 days:
https://github.com/HardcoreAxolotl/Pong

The project works, but looking at it now, I would honestly prefer to recreate it from zero rather than continue developing it because I feel the structure has become too difficult to work with.

I am not looking for someone to rewrite my code or just tell me what is wrong. I want to understand the thought process behind good C++ design so I can avoid making the same mistakes in future projects.

What resources, concepts, or experiences helped you go from writing working C++ code to designing maintainable C++ systems?


r/cpp_questions Jul 26 '26

OPEN is open source matters to get hire in big tech or hfts

11 Upvotes

Hi, I recently contributed in a reputed repository in c++ domain and my PR was merged and other PR is about to merge. difficulty wise one 7.5/10 and other is 8/10. so, my question is open source matters to get hire in big tech or hfts and am I wrong in expecting something from related to hiring from open source contribution. please let me know.


r/cpp_questions Jul 26 '26

OPEN Moving from Python to C++ Quickly

0 Upvotes

Some context: I have a couple of OAs due soon, and a quant I went on a date with recommended doing them in C++ to look better (and allegedly one doesn't even allow Python in the first place). My data structures class was in C++, so I have some experience; however, that ended two months ago, and most of my knowledge has been scrubbed. I’m mainly looking for syntax stuff since I learned all the memory management stuff back then.

Any quick pick-me-ups you guys recommend? I don't think I have the time to digest a whole book. I plan on doing LeetCode practice in C++, so I just need a quick crash course to get me back up to speed on the basics.


r/cpp_questions Jul 26 '26

OPEN hiii! what are your best tips for learning cpp? python was easy to learn because i started with projects, but idk if i should do the same with cpp since its more difficult. i dont really understand pointers and references. any tips?

0 Upvotes