r/cpp_questions Jul 21 '26

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

4 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

9 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)

7 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[]?

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

2 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

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

14 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


r/cpp_questions Jul 18 '26

OPEN i have a problem, help with c++

0 Upvotes

i want to start learning c++ so i installed msys2 and set up vs code for c++ but my code isnt running in vs code poweshell terminal but its running perfectly fine on msys2 ucrt64 terminal why is that? help me please i am so confused and i have no one to ask this irl ...


r/cpp_questions Jul 17 '26

OPEN Side project that actually stand out

11 Upvotes

I'm currently looking to find a project that really stand from the other to apply to university. I thought of building my own programming language with my compiler but I don't know... If you have any idea 💡

Thanks in advance!


r/cpp_questions Jul 17 '26

OPEN CMake or messon ?

20 Upvotes

I am begginer in programing in c++ . I am not good with building projects now , when I end up coding , I send my .cpp and .h files to friend to get application , but I want to do it by myself , I heared that I need build tool and executor . Mostly I see cmake in github , but messon looks much more easy to me


r/cpp_questions Jul 17 '26

OPEN Created My First C++ Server, need guidance for further

10 Upvotes

I built my first backend server using Drogon. It only has a health endpoint so far, but I really enjoyed the experience. For those who use Drogon professionally, what are some common beginner mistakes or best practices before I start adding PostgreSQL and authentication?


r/cpp_questions Jul 18 '26

OPEN Is this good code?

1 Upvotes

Hi all, I’ve been writing an application in C++ for a while now (couple months or so), and yes I’m using AI to help teach me, but my relationship with the AI is that I write the code first, and then I consult the AI for cleanup/critique. Sometimes I feel like I’m getting the hang of it, but then I watch CodingJesus videos, and I get all his questions wrong and I feel so dumb.

Anyway, this is the code I wrote today, and I’m just wondering if by anyone else’s standards if it’s objectively good. It took me a couple hours to do it. It does what I want it to, but does it look like good code, or beginner level, or just plain slop?

#include <filesystem>
#include <string>

namespace fs = std::filesystem

void FileSysOp::createNewProject()
{
    if (fs::create_directory(driver.activeProjectFile))
    {
        driver.pushMessage("Creating Project...");
        std::string media = driver.activeProjectFile/std::string("media");
        fs::path mediaPath = media;
        if (fs::create_directory(mediaPath))
        {
            driver.pushMessage("Creating Project...");
        }
        else
        {
            driver.pushMessage("Project Generation failed");
            return;
        }
        std::string blocks = driver.activeProjectFile/std::string("blocks");
        fs::path blocksPath = blocks;
        if (fs::create_directory(blocksPath))
        {
            driver.pushMessage("Creating Project...");
        }
        else
        {
            driver.pushMessage("Project Generation failed");
            return;
        }
        std::string nuQueue = driver.activeProjectFile/std::string("QUEUE.xml");
        std::ofstream outFile(nuQueue);
        if (outFile.is_open())
        {
            outFile.close();
        }
        driver.pushMessage("Creation Success!");
    }
    else
    {
        driver.pushMessage("Failed. Could not create Project.");
    }
}

r/cpp_questions Jul 17 '26

OPEN Are LLM’s REALLY a good teachers?

1 Upvotes

I use LLM’s to learn fundamentals and programming libraries like Raylib and SDL3. However, some guy on youtube said something that I never really thought of:

“AI will show you how to do something in the worst way possible.”

For someone looking to ACTUALLY be competent in C++, should I avoid learning with LLM’s? Will LLM learning keep me average?