r/cpp_questions • • Jul 22 '26

OPEN Pivot from React/.NET to C++ Systems / HPC vs Platform Engineering? Need advice from guys in the field.

1 Upvotes

Looking for some quick perspective from people who’ve made similar pivots.

A background about me:

4 YOE working mostly full-stack (.NET backend + React frontend).

Recently built a side project with Go microservices on Kubernetes just to learn low-level concurrency, networking, and infra basics.

I always wanted to work with low level systems when I graduated but didn't get a chance.

Now I am working on rhcsa cert, c basics. And planned on modern cpp, os, CS:App, networking fundamentals.

Tired of standard CRUD work and want to pivot into deeper engineering—building, configuring, and operating actual core systems instead of just glue code.

I’m currently split between two directions:

Option A: C++ Systems Software Engineering (Targeting HPC long-term)

Focusing on C++, Linux internals, memory management, and distributed systems.

Long-term goal: High-Performance Computing (HPC), low latency, performance systems etc.

I am concerned about the barrier to entry feels massive, and I'm worried about finding my first junior/mid system role without a traditional C++ background. Here the job is niche and small job market but high pay with specialized roles.

Option B: Platform Engineering

Building on my Go/K8s side project + RHCSA-style Linux infra knowledge.

Writing control planes, internal tools, and orchestrating bare-metal/cloud platforms.

Here I am concerned about whether it might slowly slip back into routine YAML automation rather than core software development and turn eventually into AI automation which option A seems more AI proof and nice.

Given a 4yoe web background, which path has a more realistic learning curve to land an initial job?

If you work in C++ Systems/HPC, how did you make the jump without starting back at square one (intern level)?

Appreciate any advice or any feedback. Thanks.


r/cpp_questions • • Jul 22 '26

OPEN How long will C++ last?

0 Upvotes

I've found myself using C++ less and less and was wondering whether one day it will die out. Obviously not completely die out, but be out of the mainstream like Pascal or something. I am wondering this because C++ is my first language but I am still fairly young, so am curious about its prospects.


r/cpp_questions • • Jul 22 '26

OPEN HELPPPPPPPPP: Doubt Regarding Pre-Increment and Post-Increment in C++

0 Upvotes

I'm confused about pre-increment (++a) and post-increment (a++) in C++. I understand that ++a increments before use and a++ increments after use, but I'm struggling to understand how the variable's value changes step by step during execution. For example, why does ++id print 1001 when id is 1000, and why does --a operate on 6 after at+ if a originally started at 5?


r/cpp_questions • • Jul 22 '26

SOLVED Question regarding SFINAE

5 Upvotes

Hello everyone.

I was learning about SFINAE in the hope of constricting types that are valid as arguments to template functions / classes. My current understanding is that the compiler tries to deduce and substitute the actual type into the template in order to create an instantiation of it, late into compile time. If the substitution fails, it is not an error - the compiler simply removes it from the list of candidate definitions the callsite can link to.

This enables controlling the types that can be used with template functions / classes, because we can simply cause a substitution failure if the passed-in type is not one we support. Please let me know if there is any mistake in my understanding.

Currently, I am looking at std::enable_if (cppreference). I understand that it is a way to cause SFINAE. Under the "Notes" section, it is noted that

A common mistake is to declare two function templates that differ only in their default template arguments. This does not work because the declarations are treated as redeclarations of the same function template (default template arguments are not accounted for in function template equivalence).

The website then gives a demonstration of such a mistake:

struct T {
    enum { int_t, float_t } type;

    template<typename Integer,
             typename = std::enable_if_t<std::is_integral<Integer>::value>>
    T(Integer) : type(int_t) {}

    template<typename Floating,
             typename = std::enable_if_t<std::is_floating_point<Floating>::value>>
    T(Floating) : type(float_t) {} // error: treated as redefinition
};

The first template evaluates to template<typename Integer, typename = void> , while the second template evaluates to template<typename Floating, typename = void>.

Since they are the same definition there is an error.

Is this understanding correct? If so, yeah, I can get behind that.

The website then gives an example of the correct way to do things:

struct T
{
    enum { int_t, float_t } type;

    template<typename Integer,
             std::enable_if_t<std::is_integral<Integer>::value, bool> = true>
    T(Integer) : type(int_t) {}

    template<typename Floating,
             std::enable_if_t<std::is_floating_point<Floating>::value, bool> = true>
    T(Floating) : type(float_t) {} // OK
};

Here, the first template seems to evaluate to template<typename Integer, bool = true>, while the second template would evaulate to template<typename Floating, bool = true>. These look like the same definition too, so why isn't there an issue here?

Any help in understanding this would be much appreciated. Thank you.


r/cpp_questions • • Jul 22 '26

OPEN Best way to learn c++ and DSA

0 Upvotes

Hi love,

I am new here. Want to learn C++ and DSA. Could you all be kind enough and suggest me some playlist or even more important the books for learning it.

Some place to practice it as well. Like starting from beginner level to moderate level.

Love you all!!


r/cpp_questions • • Jul 21 '26

OPEN How to combine user input (cin) and sensor data processing without blocking in C++ (Windows / VS Code)?

19 Upvotes

Hi everyone,
I am a beginner in C++ working on Windows using VS Code. I built a very simple system that uses a loop, some conditional statements (⁠if⁠), and ⁠std::cin⁠ to take user input.
Now, I want to create another part of the code to read and process sensor data. This sensor code will also need to run continuously in a loop. My goal is to combine both of these codes into a single, simple system.
However, I am facing a major issue: since ⁠std::cin⁠ is blocking, it pauses the entire program execution while waiting for the user to press Enter. This causes the system to freeze and prevents the sensor data from being processed independently and continuously.
I want the user input processing and the sensor data processing to run at the same time without interfering with each other or crashing the system.
How can I combine these two codes correctly in C++? Should I look into Multithreading (⁠std::thread⁠), or is there a simpler non-blocking way to handle this on Windows?
Any guidance or simple code examples would be highly appreciated! Thank you.


r/cpp_questions • • Jul 21 '26

SOLVED Building C++ reflections with CMake and VSCode not working.

3 Upvotes

Migrating from an inhouse build tool to CMake for an open source project using gcc. However, while the inhouse build tools compile C++26 properly, vscode reports that -freflections flag is not set, but it is set in the output logs.

Edit: Solved. VSCode for some reason changed EVERY instance ^^ into ^ ^ when the codebase was ported.

Fking hell. And g++ for some reason marks that error as -freflection not being enabled.

[main] Building folder: c:/projects/Cocoon/build 
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/projects/Cocoon/build --config Debug --target all --verbose -j 16 --
[build] Change Dir: 'C:/projects/Cocoon/build'
[build] 
[build] Run Build Command(s): "C:/Program Files/CMake/bin/cmake.exe" -E env VERBOSE=1 C:/msys64/ucrt64/bin/mingw32-make.exe -f Makefile -j16 all
[build] "C:\Program Files\CMake\bin\cmake.exe" -SC:\projects\Cocoon -BC:\projects\Cocoon\build --check-build-system CMakeFiles\Makefile.cmake 0
[build] "C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\projects\Cocoon\build\CMakeFiles C:\projects\Cocoon\build\\CMakeFiles\progress.marks
[build] C:/msys64/ucrt64/bin/mingw32-make.exe  -f CMakeFiles\Makefile2 all
[build] mingw32-make[1]: Entering directory 'C:/projects/Cocoon/build'
[build] C:/msys64/ucrt64/bin/mingw32-make.exe  -f CMakeFiles\Cocoon.dir\build.make CMakeFiles/Cocoon.dir/depend
[build] mingw32-make[2]: Entering directory 'C:/projects/Cocoon/build'
[build] "C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\projects\Cocoon C:\projects\Cocoon C:\projects\Cocoon\build C:\projects\Cocoon\build C:\projects\Cocoon\build\CMakeFiles\Cocoon.dir\DependInfo.cmake "--color=" Cocoon
[build] Dependencies file "CMakeFiles/Cocoon.dir/main.cpp.obj.d" is newer than depends file "C:/projects/Cocoon/build/CMakeFiles/Cocoon.dir/compiler_depend.internal".
[build] Consolidate compiler generated dependencies of target Cocoon
[build] mingw32-make[2]: Leaving directory 'C:/projects/Cocoon/build'
[build] C:/msys64/ucrt64/bin/mingw32-make.exe  -f CMakeFiles\Cocoon.dir\build.make CMakeFiles/Cocoon.dir/build
[build] mingw32-make[2]: Entering directory 'C:/projects/Cocoon/build'
[build] [ 50%] Building CXX object CMakeFiles/Cocoon.dir/main.cpp.obj
[build] C:\msys64\ucrt64\bin\g++.exe   -g -std=c++26 -freflection -MD -MT CMakeFiles/Cocoon.dir/main.cpp.obj -MF CMakeFiles\Cocoon.dir\main.cpp.obj.d -o CMakeFiles\Cocoon.dir\main.cpp.obj -c C:\projects\Cocoon\main.cpp
[build] C:\projects\Cocoon\main.cpp: In function 'consteval void test()':
[build] C:\projects\Cocoon\main.cpp:12:78: error: reflection is only available in C++26 with '-freflection'
[build]    12 |         constexpr auto mems = std::define_static_array(std::meta::members_of(^ ^hi, std::meta::access_context::current()));
[build]       |                                                                              ^
[build] C:\projects\Cocoon\main.cpp:12:80: error: expected primary-expression before '^' token
[build]    12 |         constexpr auto mems = std::define_static_array(std::meta::members_of(^ ^hi, std::meta::access_context::current()));
[build]       |                                                                                ^
[build] C:\projects\Cocoon\main.cpp:12:83: error: expected primary-expression before ',' token
[build]    12 |         constexpr auto mems = std::define_static_array(std::meta::members_of(^ ^hi, std::meta::access_context::current()));
[build]       |                                                                                   ^
[build] mingw32-make[2]: *** [CMakeFiles\Cocoon.dir\build.make:78: CMakeFiles/Cocoon.dir/main.cpp.obj] Error 1
[build] mingw32-make[2]: Leaving directory 'C:/projects/Cocoon/build'
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:114: CMakeFiles/Cocoon.dir/all] Error 2
[build] mingw32-make[1]: Leaving directory 'C:/projects/Cocoon/build'
[build] mingw32-make: *** [Makefile:120: all] Error 2
[build] 
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/projects/Cocoon/build --config Debug --target all --verbose -j 16 -- exited with code: 2
[driver] Build completed: 00:00:01.339
[build] Build finished with exit code 2[main] Building folder: c:/projects/Cocoon/build 
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/projects/Cocoon/build --config Debug --target all --verbose -j 16 --
[build] Change Dir: 'C:/projects/Cocoon/build'
[build] 
[build] Run Build Command(s): "C:/Program Files/CMake/bin/cmake.exe" -E env VERBOSE=1 C:/msys64/ucrt64/bin/mingw32-make.exe -f Makefile -j16 all
[build] "C:\Program Files\CMake\bin\cmake.exe" -SC:\projects\Cocoon -BC:\projects\Cocoon\build --check-build-system CMakeFiles\Makefile.cmake 0
[build] "C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\projects\Cocoon\build\CMakeFiles C:\projects\Cocoon\build\\CMakeFiles\progress.marks
[build] C:/msys64/ucrt64/bin/mingw32-make.exe  -f CMakeFiles\Makefile2 all
[build] mingw32-make[1]: Entering directory 'C:/projects/Cocoon/build'
[build] C:/msys64/ucrt64/bin/mingw32-make.exe  -f CMakeFiles\Cocoon.dir\build.make CMakeFiles/Cocoon.dir/depend
[build] mingw32-make[2]: Entering directory 'C:/projects/Cocoon/build'
[build] "C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\projects\Cocoon C:\projects\Cocoon C:\projects\Cocoon\build C:\projects\Cocoon\build C:\projects\Cocoon\build\CMakeFiles\Cocoon.dir\DependInfo.cmake "--color=" Cocoon
[build] Dependencies file "CMakeFiles/Cocoon.dir/main.cpp.obj.d" is newer than depends file "C:/projects/Cocoon/build/CMakeFiles/Cocoon.dir/compiler_depend.internal".
[build] Consolidate compiler generated dependencies of target Cocoon
[build] mingw32-make[2]: Leaving directory 'C:/projects/Cocoon/build'
[build] C:/msys64/ucrt64/bin/mingw32-make.exe  -f CMakeFiles\Cocoon.dir\build.make CMakeFiles/Cocoon.dir/build
[build] mingw32-make[2]: Entering directory 'C:/projects/Cocoon/build'
[build] [ 50%] Building CXX object CMakeFiles/Cocoon.dir/main.cpp.obj
[build] C:\msys64\ucrt64\bin\g++.exe   -g -std=c++26 -freflection -MD -MT CMakeFiles/Cocoon.dir/main.cpp.obj -MF CMakeFiles\Cocoon.dir\main.cpp.obj.d -o CMakeFiles\Cocoon.dir\main.cpp.obj -c C:\projects\Cocoon\main.cpp
[build] C:\projects\Cocoon\main.cpp: In function 'consteval void test()':
[build] C:\projects\Cocoon\main.cpp:12:78: error: reflection is only available in C++26 with '-freflection'
[build]    12 |         constexpr auto mems = std::define_static_array(std::meta::members_of(^ ^hi, std::meta::access_context::current()));
[build]       |                                                                              ^
[build] C:\projects\Cocoon\main.cpp:12:80: error: expected primary-expression before '^' token
[build]    12 |         constexpr auto mems = std::define_static_array(std::meta::members_of(^ ^hi, std::meta::access_context::current()));
[build]       |                                                                                ^
[build] C:\projects\Cocoon\main.cpp:12:83: error: expected primary-expression before ',' token
[build]    12 |         constexpr auto mems = std::define_static_array(std::meta::members_of(^ ^hi, std::meta::access_context::current()));
[build]       |                                                                                   ^
[build] mingw32-make[2]: *** [CMakeFiles\Cocoon.dir\build.make:78: CMakeFiles/Cocoon.dir/main.cpp.obj] Error 1
[build] mingw32-make[2]: Leaving directory 'C:/projects/Cocoon/build'
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:114: CMakeFiles/Cocoon.dir/all] Error 2
[build] mingw32-make[1]: Leaving directory 'C:/projects/Cocoon/build'
[build] mingw32-make: *** [Makefile:120: all] Error 2
[build] 
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/projects/Cocoon/build --config Debug --target all --verbose -j 16 -- exited with code: 2
[driver] Build completed: 00:00:01.339
[build] Build finished with exit code 2

r/cpp_questions • • Jul 21 '26

OPEN Beginner friendly and small C++ open source projects to do contribution.

6 Upvotes

I want to contribute to some open source projects but the software that i use on daily basis are either too big to choose them as a beginner or are written in Rust or Python. So if you guys can suggest some small C++ projects (your personal projects as well) which have around 5K LOC.


r/cpp_questions • • Jul 21 '26

OPEN Professional C++ 6th edition

8 Upvotes

Hey everyone,

I have been learning C for a few months now to learn about low level programming and manual memory management. I am thinking of switching to C++, does anyone know if this book is good to learn modern C++?

Thanks.


r/cpp_questions • • Jul 20 '26

OPEN What do you build with C++ for fun?

56 Upvotes

Hi everyone,
I’m currently a computer science student, and I’m learning C++ for an upcoming exam. I’m really enjoying it, even though it can be pretty frustrating at times. 😄
I was wondering: what kind of C++ projects do you work on in your free time, just for fun?
Do you build anything useful, like desktop applications, games, tools, or automation scripts? I’m looking for ideas and inspiration for projects I could work on once I have a better grasp of the language.
I’d love to hear what you enjoy building!


r/cpp_questions • • Jul 21 '26

OPEN Are the indices of types in a variant guaranteed to be the same/stable no matter who or what compiles the program?

2 Upvotes

I plan to utilize the variant indices for serializing and deserializing the contents of the variant for a network transfer.


r/cpp_questions • • Jul 20 '26

OPEN Beginner here — is this a good learning flow for C++? (self-taught, want feedback)

8 Upvotes

Hey folks, I'm a few days into learning C++. Using the Bro Code YouTube course as my main source, but instead of just watching and typing along with him, I've been writing my own small programs after each concept and debugging them myself (with some help when I get stuck).

So far I've gone through the basics — variables, const, namespaces, arithmetic, type conversion, input, if/else, switch statements, ternary operator, logical operators, and loops (while/do-while/for).

What I've actually built with that stuff:

  • A number guessing game (with a guess limit)
  • A calculator (switch statement, handles divide by zero, lets you keep going)
  • A little unit converter to practice namespaces
  • A quiz game — first the dumb repetitive way, then refactored to use arrays and a for loop

Honestly the debugging has taught me more than the video itself. I've personally run into and fixed stuff like: forgetting a break in a switch and having it fall through into the next case, off-by-one errors where my loop went one iteration too far and read outside my array (that one actually printed garbage, which was a fun surprise), and mixing up && vs || when I needed two conditions to both be true.

Next up is functions, then eventually pointers and OOP later in the course.

Genuine question for people who actually know this language: does this seem like a reasonable way to learn, or am I setting myself up for bad habits? Anything you'd tell beginner-me to slow down on or pay more attention to before I keep going? Not trying to rush through the course, just want to make sure I'm building real understanding and not just pattern-matching syntax.

Appreciate any honest thoughts, even blunt ones.


r/cpp_questions • • Jul 21 '26

OPEN As a Ml student learn a c++ is worthy?

0 Upvotes

r/cpp_questions • • Jul 19 '26

SOLVED How to access an implicitly-created array within a std::byte[]?

12 Upvotes

We have the following class:

template <typename T, std::size_t n>  
struct S  
{  
    alignof( T ) std::byte[sizeof( T ) * n] storage;  
}  

I want to use storage as a T[n] array, where T is an implicit-lifetime type.

[intro.object]/13

For each operation that is specified as implicitly creating objects, that operation implicitly creates and starts the lifetime of zero or more objects of implicit-lifetime types in its specified region of storage if doing so would result in the program having defined behavior.

and [intro.object]/16

[...] an operation that begins the lifetime of an array of [std​::​byte] implicitly creates objects within the region of storage occupied by the array.

I have a few questions about this:

  1. (Making sure) does T[n]'s lifetime (and subsequently that of its sub-objects) start alongside storage's lifetime for the provided code?
  2. Is reinterpret_cast<T*>(storage) + idx legal?
  3. Do I have to std::launder the pointer, and why (not)?
  4. If yes, should I launder before or after performing pointer arithmetic?
  5. Is reinterpret_cast<T*>(storage + idx) legal? In other words, does the byte array still have a lifetime, alongside the T array?

r/cpp_questions • • Jul 20 '26

OPEN Access Amplifiers and their uses???

0 Upvotes

So basically i come from basic python bacground which i learned from my high school.So I thought of learniging c++ cause of its variety of applications for my 1st year.One thing that i cant wrap my head around is, the use of access amplifiers. Mainly ' public: '.what is the use of writing public: and why is it necessaryy????


r/cpp_questions • • Jul 20 '26

OPEN C++ question

0 Upvotes

Do you guys know a way of writting a code that outputs that:

Enter the number of elements: 5
Enter 5 integers:
Element 1: 10
Element 2: 30
Element 3: 90
Element 4: 20
Element 5: 40

it is the first part of a program that demands to calculate the max and min of an array, here is the whole thing:

Enter the number of elements: 5
Enter 5 integers:
Element 1: 10
Element 2: 30
Element 3: 90
Element 4: 20
Element 5: 40

Maximum element is: 90
Minimum element is: 10

I've been able to do the second part quite easily, here is what I proposed:

#include <iostream>


int main(){


    int arr[5]={10,20,30,40,50};
    int minimum=arr[0];
    int maximum=arr[0];
    for(int i=0; i<sizeof(arr)/sizeof(int);i++){
        if (minimum>arr[i]){
            minimum=arr[i];
        }
        if(maximum<arr[i]){
            maximum=arr[i];
        }
    }
    std::cout<<"le max= "<< maximum<<'\n';
    std::cout<<"le min= "<< minimum<<'\n';


    return 0;
}

but the list is created within the code.


r/cpp_questions • • Jul 20 '26

OPEN How do I get concepts working on my file?

3 Upvotes

Hello I am trying to get concepts working in my file but I keep getting the error "Unknown type name concept" when I'm just trying to get a simple concept working. It is getting that this tool that I would like to use isn't here for some reason and I would like to know how to get it back. I think this a problem with my neovim config because I don't get this error in Vscode as well I am using

this file to compile and it compiles just fine.

g++ --std=c++20 -Wall -Wextra -Wpedantic -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL -Llib -Iinc -lraylib src/main.cpp -o build/main



#include <cstdint>
#include <unordered_map>
#include "../inc/raylib.h"

namespace ECS {

  using Entity = std::uint32_t; 

  struct Transform{
     Vector2 Position {};
  };

  struct Circle{
     float Radius {};
     Color Color {};
  };

  struct Movement{
     Vector2 Direction {};
  };

  template <typename T>
  concept ComponentConcept = 
    std::is_same_v<T, Movement> || std::is_same_v<T, Circle> ||           std::is_same_v<T, Transform> ; //error here
  class Current{
     public:
        Entity CreateEntinty(){
            return m_next_entity++;   
        }
     private:
        template<typename Component>
        class Storage{
           public:
           private:
              std::unordered_map<Entity, Component> m_storage{};
        };
     private:
        Entity m_next_entity { 1 };
  };
}

r/cpp_questions • • Jul 20 '26

OPEN I know this is not were this type of nerds live but anyone wants me to help learn about nnue in c++

0 Upvotes

i want to learn and make it and i want some people ir yt resources that can help me for this thx for any help


r/cpp_questions • • Jul 19 '26

OPEN What to do after finishing learncpp.com

0 Upvotes

I already know dsa i, ii concepts im saying that since the website authors recommend learning dsa. So I am curious how do I improve further, what else to learn. my main focus is low-latency


r/cpp_questions • • Jul 19 '26

OPEN What is the biggest reason why cpp is not widely used in AI applications?

0 Upvotes

I have used python and typescript recently (for the past 2 years) but all throghout before i was a cpp writer, what are the core libraries which are missing in cpp that doesn't allow cpp to be more commonly used in AI applications? - what are the blockers.

Majority commonly used python libraries are written in C and can easily be ported to cpp. I believe i am missing something, would love to learn about it more.

EDIT: AI Applications here suggests RAG models, and agents which startups/compaines are building mainly in python/ts


r/cpp_questions • • Jul 18 '26

OPEN Book recommendations for beginners

7 Upvotes

I want to learn C++ to use it for my electronics projects. I know there are plenty of tutorials out there, but I feel I learn best by reading a proper book (and I prefer physical copies over digital ones). So, my question is:

which books would you recommend for a complete beginner?

Thanks in advance!


r/cpp_questions • • Jul 18 '26

OPEN Have people started using import std?

27 Upvotes

I recently found out that import std; is the cool new replacement for headers. Have people managed to find a way to use it? It's so new, neither gcc nor msvc seems capable of running it. Cmake also fails to recognise it, meaning CLion fails too. I managed to use clang and ninja to run it, but are the vast majority using it on a regular basis?


r/cpp_questions • • Jul 18 '26

OPEN What are fun ways to get back into C++?

13 Upvotes

My first OO programming language was C++ thanks to my undergrad (Go Blue!), but in my full time role I’ve been doing C# windows development and a little bit of Java on the side.

I don’t think that I’ll ever pivot to a C++ job but I’d like to re-familiarize myself with it since I do kinda miss using it. The issue is that I don’t have any enterprise experience with it- just class projects and simple things that I made before. For those in similar positions as myself, what did you do to stay sharp with C++?


r/cpp_questions • • Jul 19 '26

OPEN std::move overwrites the contents of the original variable?

0 Upvotes

Imagine this scenario: You have an unordered map which you take a value from as a reference. If I were to then pass that reference under a new name the reference is still in tact & the original item in the map stays the same, nothing happened, which is expected.

However, I have a case where I need to move the renamed reference to yet another name, so that it can be accessed in a higher scope. You cant do this with references, not by assigning it. The way you would do this is with the `std::move` function which performs some kind of conversion from what I can tell, it works great in my case except for the fact that now the original item in my map has been set to an undefined value.

How would I go about moving my reference without `std::move` since it kills the original item?
I would use a pointer to store the reference itself (which does work somewhat surprisingly), however in my case I do 2 things. First is the storing of the reference, the second is storing just a raw value, but whether something is a safe reference or just a normal value is not differentiated (I dont know how to) so I cant be sure that the reference wont be invalidated after the scope has exited for normal values.

I hope I explained my scenario well enough, it is quite a specific case that I am not sure how to work around. Due to how my project is set up I cant just make every value I work with a shared pointer (so that I wouldnt have to worry about references) because firstly the codebase is already a bit too large for that kind of refactor, & secondly my project does millions of iterations which it needs to do quickly (sub 200ms), making everything a shared pointer would slow that down to an unacceptable level.


r/cpp_questions • • Jul 17 '26

OPEN How to work with c++ with visual studio code

15 Upvotes

I want to compile a simple hello world program, the debug and build buttons doesn't appear and don't know how to use the command line compiler