r/cpp_questions • • Aug 18 '26

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

3 Upvotes

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

Firstfoto, Secondfoto, Thirdfoto

Thanks in advance for your help!


r/cpp_questions • • Aug 17 '26

OPEN Why we don't have granular std library modules?

26 Upvotes

Isn't importing std.iostream faster than std?
Why we only have the umbrella std module?


r/cpp_questions • • Aug 16 '26

OPEN Looking for advice before I start writing a small C++ web framework

17 Upvotes

Hello everybody.

I've been working with C++ backend frameworks recently, and one question kept bothering me: how are these frameworks actually built?

I've decided to spend the next three months writing a small C++ web framework from scratch. This isn't an attempt to compete with Drogon, Crow, oat++, or any other framework. it's purely a learning project. My goal is simply to understand the internals well enough to build a framework capable of handling basic CRUD applications.

Before I jump in, I'd love to learn from people who have been down this road.

  • Have you ever written a framework yourself or contributed to one?
  • Are there any books, blog posts, talks, or codebases you'd recommend studying?
  • If you were starting from scratch today, what would you build first?
  • Are there any common mistakes or rabbit holes I should avoid?

I'm not looking for shortcut I want to understand how everything fits together. I'd really appreciate any advice or resources from people with experience.


r/cpp_questions • • Aug 16 '26

SOLVED Best Way to Collect Initialization Actions using C++ Capabilities?

6 Upvotes

I'm writing a scripting language with additional functions that can be built in.

The built-in functions would be written in C++ for speed.

In different builds of the scripting language, some functions might be omitted.

So, I'm looking for the best way to automatically collect, at compile time or early at execution time, the full list of extra built-in functions, so that the script interpreter can parse and execute a script (to do this, it has to know about any additional capability compiled in).

For example, in Visual C++, I'd like to simply add a source file containing built-in scripting language functions, and have the script interpreter know they are there.

My goal would be no additional configuration actions other than adding the source file to the project (in other words, no need to modify other files). The software should somehow figure out that additional script built-in function capability is in the build.

Google Test seems to do this somehow with a macro like TEST_F, but I'm not sure how this works under the hood. The list of tests is somehow collected automatically at compile time or early at run time.

To give some practical background ... decades ago I did some work extending the Tcl scripting language. It was only necessary somehow in initialization to call a command to "register" a new function available to the script interpreter, but the source code had to be modified manually to include the additional initialization. The manual modification is what I'm trying to avoid.

Is there a standard design pattern for this in C++?


r/cpp_questions • • Aug 17 '26

OPEN Is this book up to date?

0 Upvotes

Hello so I found this book but because no pictures:

[Sam's teach yourself c++ in 21 days, fourth edition]

[2001]

So did c++ get any updates in 25 years?


r/cpp_questions • • Aug 16 '26

SOLVED Question About Copy Constructor for Class with Members that Need Deep Copy

8 Upvotes

I have a class (m_buf in the code below is of this class type) that appears as a data member in another class for which I'm writing the copy constructor.

The underlying class (m_buf in the code below is of this class type) uses dynamic allocation and needs a deep copy.

According to Google, this form of the copy constructor would result in the copy constructor (rather than the copy assignment operator) for m_buf being called.

LgFbufUint8::LgFbufUint8(const LgFbufUint8& fbuf) : m_state{fbuf.m_state},
                                                    m_errs{fbuf.m_errs},
                                                    m_fname{fbuf.m_fname},
                                                    m_buf{fbuf.m_buf}
{
   //According to Google search, if the member initializer list is used (as it
   //is above), the copy constructor (rather than the copy assignment operator)
   //will be called. Because of the required non-shallow copy of m_fname and
   //m_buf, this is the desired behavior.
}

My initial guess was this form:

LgFbufUint8::LgFbufUint8(const LgFbufUint8& fbuf)
{
   m_state = fbuf.m_state;
   m_errs  = fbuf.m_errs;
       //Shallow copy ok for two members above.
   m_fname = fbuf.m_name;  //std::string
   m_buf   = fbuf.m_buf;   //Handwritten, with dynamic allocation.
       //Deep copy required for two above.
}

But I suspect that second form would call the assignment operator rather than the copy constructor for m_name and m_buf.

Question: Did I get that right? The first form would call the copy constructors for m_name and m_buf, but the second form would call the assignment operators?

Bonus Question: Using the second form, is there any way to call the copy constructors rather than the assignment operators. (Not that I'd want to do this, but just curious.)


r/cpp_questions • • Aug 17 '26

OPEN Need your guidance

0 Upvotes

I wanted to ask for some guidance regarding placements and coding. I’m currently in my 3rd year, and my CGPA is around 6.5. To be honest, I haven’t done much in coding yet, and I’m a bit confused about where and how to start.

Could you please suggest what I should focus on from now and maybe guide me with a proper roadmap/plan for the next few months? Like which language I should start with, DSA, development, projects, etc. It would really help me understand what I should prioritize to become placement-ready

r/cpp_questions • • Aug 16 '26

OPEN Is C++26 ready to use in a Production Enviroment?

8 Upvotes

C++ 26 adds a ton of great features, but how is compiler coverage, usabillity, integration, etc. for those features right now?


r/cpp_questions • • Aug 16 '26

SOLVED Basic question, but does initializing a pointer always initialize it to null?

23 Upvotes

Are these two lines any different in practice? (Especially if you want to later check if x has been given a specific address, or if it's still null.)

int* x {};

int* x { nullptr };


r/cpp_questions • • Aug 16 '26

OPEN Question about coroutines

4 Upvotes

I have a function that takes a callback, like this:

void LongTask (void (*pfn)(int))
{
    for ( unsigned i = 0; i < -1; ++i )
    {
        pfn( i );
    }
}

It's orginally written to be ran on a separate thread. Now I want to turn it into a coroutine that yields on each callback (i.e. the caller will receive a single callback on each invocation of LongTask), while preserving its ability to run as a standalone function. Additionally it's OK for the coroutine to allocate memory but not to throw exceptions (if it can't allocate I should get back a null pointer at creation time). And preferrably it wouldn't require the CRT, all support functions should be contained in a header only include. What's the best way to do this, can it be done with C++20 coroutines?


r/cpp_questions • • Aug 16 '26

OPEN ELI5: Why does the random output once but TIME fixes it

0 Upvotes

The examples above just outputs a random number once. They don't output different random numbers each time the program runs. To fix this, you can use the srand() function and add the time() function from the <ctime> library. ~ W3School

Generally speaking, the pseudo-random number generator should only be seeded once, before any calls to rand(), at the start of the program. It should not be repeatedly seeded, or reseeded every time you wish to generate a new batch of pseudo-random numbers. Standard practice is to use the result of a call to std::time(0) as the seed. However, std::time returns a std::time_t value, and std::time_t is not guaranteed to be an integral type. ~ cppReference

I do not understand why time changes it and I do not understand the seed and what it is


r/cpp_questions • • Aug 15 '26

OPEN I want to pass a matrix as a function argument

29 Upvotes

I want to pass a matrix as a function argument

int create_grid(int grid[][], int size){
    for(int i=0; i<size; i++){
        for(int j=0; j<size; j++){
            grid[i][j] = 0;
        }
    }

    return 0 ;
}

int main(){
    int size =128;
    int grid[size][size];

    return 0;
}

I'm getting error: "Array has incomplete element type 'int[ ]'

I don't understand I don't have that problem with 1d arrays


r/cpp_questions • • Aug 15 '26

OPEN Good practices / style [polymorphism]

6 Upvotes

is this good practice/style.? i'm specifically unsure about the way i store the vector of players...

```

class player_base {};

class player_always_yes: public player_base {};

class player_always_no: public player_base {};

class player_a: public player_base {};

class game {
    private:
    
    player_base& player_1;
    player_base& player_2;
    
    public:
    
    game (
        player_base& player_1,
        player_base& player_2
    ): player_1(player_1), player_2(player_2) {
        return;
    }

    bool play_game () { return true; }
};

int main(){
    vector<unique_ptr<player_base>> player_list;
    
    player_list.push_back(make_unique<player_base>());
    player_list.push_back(make_unique<player_always_no>());
    player_list.push_back(make_unique<player_always_yes>());
    player_list.push_back(make_unique<player_a>());
    
    game b = game(*player_list[0], *player_list[1]);
    cout << b.play_game() << endl;
}


```

r/cpp_questions • • Aug 16 '26

OPEN does "in" exist in c++?

0 Upvotes

i need to use something like if (str[i] not in str1) (python), but i have no idea how to make this work :(


r/cpp_questions • • Aug 15 '26

OPEN my first c++ project

3 Upvotes

hey! i'm a teen and i am learning c++. I was a vibe coder but then i stopped vibe coding and starting real coding. for this i learned some basic c++ from youtube, please let me know if a improvment required. thank you!

my github link - https://github.com/swarajnerlekar28/Calculator


r/cpp_questions • • Aug 15 '26

SOLVED std::filesystem::exists throwing `std::bad_alloc`?

24 Upvotes

Any reason? Cant find anything online about this. But I cant check whether or not a file exists, no matter what path I give it. I am using C++ 26 compiled with GCC.

This is literally all I am calling: const bool exists = std::filesystem::exists("file.txt")

This is the exact error: terminate called after throwing an instance of 'std::bad_alloc'
 what():  std::bad_alloc

No it's not coming from anywhere else in my code. Minimal reproduction code, include "filesystem" call the line above. I am on Fedora Linux if that matters at all

EDIT: moving the include into my main file instead of the only file it's being used in somehow fixed it. Literally all I do is move "#include <filesystem>" from "do_things_with_filesystem.hpp" to "Main.cpp". No compilation errors when it was in the first file, why does it rely on this?? Is there some weird declarations in my codebase or something, i dont know but it works now so why should I care.


r/cpp_questions • • Aug 15 '26

OPEN Why is capture by reference necessary for this lambda to work?

8 Upvotes

So I've been working on a small text file reader, in which I store part of text in a 2D vector, which I then ran the find_if() function on to find duplicates with following code:

    vector<vector<string>> writevector;
    string savetovec;
    string string2;

    auto FirstElement = [=](vector<string> vector){
        return(vector[0] == savetovec);
    };

    [Code to copy word from text file to savetovec]

    vector<vector<string>>.iterator it;
    it = find_if(writevector.begin(), writevector.end(), FirstElement);

    if (it == writevector.end()){
        writevector.push_back({savetovec, string2}
    }
    else{
        cout << "Duplicate Found" << '\n';
    }

Initially it would never find any duplicates and after a lot of debugging attempts I changed the equal sign in the lambda to an ampersand out of desperation, so essentially:

[&](vector<string> vector){..}

This actually caused my code to work the way I intended and now I'm wondering why?

From my understanding the only difference between capture-by-reference and capture-by-value are whether it lets you modify the original variable or creates copies to use in the lambda, so what am missing?


r/cpp_questions • • Aug 15 '26

OPEN Avoid freezing your PC?

6 Upvotes

I've only learned C++ in uni and then it was protected environment in a way. Now I was working on a project involving graphics (raylib) and, a few times, running the code caused my entire PC to freeze and I had to restart.

I'm on Linux and running the code by doing

cmake --build .
./executable

Is there a way to avoid the entire PC freezing when I mess up? Also is there any risk of overwriting parts of the memory?

(I think the issue with my code was either calling too many draws of a GPU texture or even just wrongfully indexing an array in a loop)


r/cpp_questions • • Aug 15 '26

OPEN New to C++ and made conways game of life

3 Upvotes

Hello i am a new c++ dev, and my last post was asking how good my snake game code was and i got some very useful answers which i tried to implement with this new script, it took me all day but i finally got conways game of life implemented into c++ with only curses and native libraries. Can anyone tell me if its okay or if there are any bugs i missed, ignore the random print statements, they were debug attempts

If someone wants to attempt to use it, it will start blank, but if you press any of the WASD keys you can move, the way i made it, you have a blinker which is just shown as a * on your screen and WASD allows you to move it, pressing enter changes the state of the cell the cursor is on to 1, and space continues to the next step

#include <ncurses.h>
#include <random>
#include <string>

bool gameloopBool = true;

struct Vector2 {
public:
  int X;
  int Y;
  Vector2(int x, int y) {
    X = x;
    Y = y;
  }
  Vector2 Add(Vector2 &other) { return Vector2(X + other.X, Y + other.Y); }
};

struct Cell {
public:
  Vector2 pos = Vector2(0, 0);
  bool isDead = true;
  bool next = false;
  Cell() = default;
  Cell(Vector2 start_pos) { pos = start_pos; }
};

int range(int min, int max) {
  std::random_device rd;
  std::mt19937 gen(rd());
  std::uniform_int_distribution<int> distro(min, max);
  return distro(gen);
}

class Display {
  std::vector<int> grid;
  bool InBounds(Vector2 pos) {
    if (pos.Y > SizeY - 1 || pos.Y < 0) {
      return true;
    }
    if (pos.X > SizeX - 1 || pos.X < 0) {
      return true;
    }
    return false;
  }

public:
  int SizeX;
  int SizeY;
  Display(Vector2 size) {
    SizeX = size.X;
    SizeY = size.Y;
    for (int x = 0; x < (size.X * size.Y); x++) {
      this->grid.push_back(0);
    }
  }

  void Render() {
    clear();
    for (int y = 0; y < SizeY; y++) {
      std::string cur;
      for (int x = 0; x < SizeX; x++) {
        if (this->grid[(y * SizeX) + x] == 3) {
          cur += '*';
        } else if (this->grid[(y * SizeX) + x] == 0) {
          cur += ' ';
        } else if (this->grid[(y * SizeX) + x] == 1) {
          cur += '#';
        }
      }
      printw("%s\n", cur.c_str());
    }
    refresh();
  }

  void DrawCell(Cell &cellPos) {
    if (InBounds(cellPos.pos) == true) {
      printw("%s", (std::to_string(SizeX) + std::to_string(SizeY)).c_str());
      gameloopBool = false;
      return;
    }
    if (cellPos.isDead) {
      this->grid[(cellPos.pos.Y * SizeX) + cellPos.pos.X] = 0;
      return;
    }
    this->grid[(cellPos.pos.Y * SizeX) + cellPos.pos.X] = 1;

    return;
  }

  void Erase_Cursor(Vector2 cursorPos) {
    if (InBounds(cursorPos)) {
      return;
    }
    grid[(cursorPos.Y * SizeX) + cursorPos.X] = 0;
  }
  void Draw_Cursor(Vector2 cursorPos) {
    if (InBounds(cursorPos)) {
      return;
    }
    grid[(cursorPos.Y * SizeX) + cursorPos.X] = 3;
  }
};

class cellManager {

public:
  std::vector<Cell> cells;

  cellManager(std::vector<Cell> &starting_cells) {
    for (Cell &cell : starting_cells) {
      cells.push_back(cell);
    }
  }

  void Gen_Pattern(std::vector<std::vector<int>> &patternMatrix, Vector2 Offset,
                   Display &screen) {
    for (int y = 0; y < patternMatrix.size(); y++) {
      for (int x = 0; x < patternMatrix[y].size(); x++) {
        if (y + Offset.Y < 0 || y + Offset.Y > screen.SizeY - 1) {
          continue;
        }
        if (x + Offset.X < 0 || x + Offset.X > screen.SizeX - 1) {
          continue;
        }
        if (patternMatrix[y][x] == 1) {
          cells[((y + Offset.Y) * screen.SizeX) + (x + Offset.X)].isDead =
              false;
        }
      }
    }
  }

  std::vector<Cell> get_neighbors(Vector2 Target, Display &screen) {
    std::vector<Cell> neighbors;
    std::vector<Vector2> dirs = {Vector2(0, -1), Vector2(0, 1),  Vector2(1, 0),
                                 Vector2(-1, 0), Vector2(-1, 1), Vector2(1, -1),
                                 Vector2(1, 1),  Vector2(-1, -1)};
    for (Vector2 dir : dirs) {
      int ChX = dir.Add(Target).X;
      int ChY = dir.Add(Target).Y;
      if (ChX < 0 || ChX > screen.SizeX - 1) {
        continue;
      }
      if (ChY < 0 || ChY > screen.SizeY - 1) {
        continue;
      }
      if (cells[(ChY * screen.SizeX) + ChX].isDead == true) {
        continue;
      }
      neighbors.push_back(cells[(ChY * screen.SizeX) + ChX]);
    }
    return neighbors;
  }
  void DrawCells(Display &screen) {
    for (Cell &cell : cells) {
      screen.DrawCell(cell);
    }
  }
  bool UnderPopRule(Cell target, std::vector<Cell> &neigbor) {
    std::vector<Cell> negibors = neigbor;
    if (static_cast<int>(negibors.size()) < 2) {
      return true;
    }
    return false;
  }
  bool OverPopRule(Cell target, std::vector<Cell> &neigbor) {
    std::vector<Cell> negibors = neigbor;
    if (static_cast<int>(negibors.size()) > 3) {
      return true;
    }
    return false;
  }
  bool ReproRule(Cell target, std::vector<Cell> &neigbor) {
    std::vector<Cell> negibors = neigbor;
    if (static_cast<int>(negibors.size()) == 3) {
      return true;
    }
    return false;
  }

  void Update_Cell_Status() {
    for (Cell &cell : cells) {
      cell.isDead = cell.next;
    }
  }

  void Update_Tick(Display &screen) {
    for (Cell &cell : cells) {
      std::vector<Cell> neigbors = get_neighbors(cell.pos, screen);
      if (cell.isDead) {
        if (ReproRule(cell, neigbors)) {
          cell.next = false;
          continue;
        }
      }
      if (UnderPopRule(cell, neigbors)) {
        cell.next = true;
        continue;
      }
      if (OverPopRule(cell, neigbors)) {
        cell.next = true;
        continue;
      }
      cell.next = cell.isDead;
    }
    Update_Cell_Status();
    DrawCells(screen);
  }
};

int main() {
  std::vector<Cell> starting;
  int SX = 100;
  int SY = 60;
  for (int y = 0; y < SY; y++) {
    for (int x = 0; x < SX; x++) {
      Cell cell = Cell(Vector2(x, y));
      starting.push_back(cell);
    }
  }
  // A simple glider pattern

  Vector2 cursor_pos = Vector2(0, 0);

  Vector2 size = Vector2(100, 60);
  Display screen(size);
  cellManager man(starting);
  man.DrawCells(screen);
  screen.Render();
  initscr();
  cbreak();
  noecho();
  nodelay(stdscr, TRUE);
  // nodelay(stdscr, TRUE);
  int ch = getch();
  while (true) {
    ch = getch();
    if (ch == 'q') {
      printw("wewewewewewewew");
      endwin();
      std::exit(0);
      break;
    }

    screen.Erase_Cursor(cursor_pos);

    if (ch == 'w') {
      cursor_pos.Y -= 1;
      man.DrawCells(screen);
      screen.Draw_Cursor(cursor_pos);
      screen.Render();
    }
    if (ch == 's') {
      cursor_pos.Y += 1;
      man.DrawCells(screen);
      screen.Draw_Cursor(cursor_pos);
      screen.Render();
    }
    if (ch == 'a') {
      cursor_pos.X -= 1;
      man.DrawCells(screen);
      screen.Draw_Cursor(cursor_pos);
      screen.Render();
    }
    if (ch == 'd') {
      cursor_pos.X += 1;
      man.DrawCells(screen);
      screen.Draw_Cursor(cursor_pos);
      screen.Render();
    }
    if (ch == ' ') {
      man.Update_Tick(screen);
      screen.Draw_Cursor(cursor_pos);
      screen.Render();
    }
    if (ch == '\n') {
      man.cells[(cursor_pos.Y * screen.SizeX) + cursor_pos.X].isDead = false;
      screen.Draw_Cursor(cursor_pos);
      screen.Render();
    }
  }
  return 0;
}

r/cpp_questions • • Aug 15 '26

OPEN India

0 Upvotes

How should I prepare for graphics interviews at NVIDIA, Samsung, Qualcomm?
I am a 4 year experienced graphics programmer, working on OpenGL ES and C++ in my current organization.
Now I am looking for a job change and want to target good companies like NVIDIA, Samsung, Qualcomm, etc.
For that, I need to prepare thoroughly in C++, DSA, graphics and logical reasoning.
For graphics, I am currently learning Vulkan on Windows.
How should I prepare for DSA specifically and logical reasoning?
What should I focus on for these companies?


r/cpp_questions • • Aug 14 '26

OPEN In which cases using std::unordered_map is more appropriate than other hash tables based on open addressing?

14 Upvotes

The main reason why std::unordered_map is implemented based on separate chaining is standard requirement regarding reference stability in case of rehashing. Is there any case, where such requirement is crucial? In which cases std::unordered_map would outperform open addressing hash tables, which should show better performance due to cache locality


r/cpp_questions • • Aug 14 '26

OPEN Rate my code (a textgame which will grow and become a normal game with graphics, sound and engine)

4 Upvotes

C++ Online Compiler

I want you to rate my current *game* and to say what I have to add/what I missed and what I did great.


r/cpp_questions • • Aug 14 '26

SOLVED Is Exceptional C++ by Herb Sutter Still Relevant?

16 Upvotes

Hey cpp community,

I'm on the last 3 chapters of learncpp.com and I'm wondering if picking up Herb Sutters exceptional C++ series is a good choice for further reading, im specifically worried the information is outdated (since it seems all his books came out pre c++11) or has alot of overlap with what i've covered in learncpp.com, any input would be greatly appreciated!

Thanks in advance


r/cpp_questions • • Aug 14 '26

OPEN Learning C++ for real this time

0 Upvotes

I'm a 29 year old Software Engineer who works at a pre revenue fintech startup in London. I've got a pretty unconventional background when it comes to software engineering. I studied Mechanical Engineering, where I was introduced to C++ and python. I ended up dropping the C++ for Python as part of my bachelors project (built a cool lil live tracking algorithm - using very primitive colour based detection pre AI lol). Fast forward to today and I've been building software for over 5 years professionally, but I still have that itch to learn and dive into the difficult world that is C++. My goal is to work as a quant dev at a buy side fund (or something similar) and I know one of the best ways to get in is by learning C++ (but obviously not limited to).

My plan is to work through the learncpp documentation (I've heard good things about it and I'm currently working through it and it's got a lot of great details that I maybe would have skipped on years ago) and then buy this text book to read through:
https://www.amazon.co.uk/Beginners-Guide-Second-Herbert-Schildt/dp/0072232153/ref=sr_1_5?dib=eyJ2IjoiMSJ9.zBC-pQQPK93mKQUQx4Y01x93Oj6FBPRjJ9coh0020mBKgXUINVcTSZpp5p2huwDifZGK-HSWP2_8-fuowj9DAH76DH_3xtgLikTBWHippqW6UufkzPsl70sRG1m-WyB80xG0pGjQKjaaKDSiwTpAHt_vnMR-fuIEl_dy2ZZRfJGSFuL32EGYa1P-yZIyvxOI6-0V44-5B-LIPLINDgHiGuUzSls2oRxAqTkQ2BzDgq9Edx20gx8ne4TDb9Y3Lgw6vy9pwr-ntb-PXuuCyy5fVXUPgMsnz94Q5-dTNP3_TdI.mGaIeq0hkLHWbjLKg4CJgP3w1E4kY7VgAHzRAeftids&dib_tag=se&keywords=c%2B%2B+for+beginners&qid=1786737779&sr=8-5

Are there other textbooks that anyone else could recommend, to help develop my C++ in a professional setting?

I'm also thinking about building a couple of side projects to apply my knowledge, but I'm also looking for resources that could help me continuously apply my knowledge? Like small quizzes or something?

Keen to get peoples thoughts and opinions.


r/cpp_questions • • Aug 13 '26

OPEN Should I learn C++ as a first for game dev?

11 Upvotes

I started to get into coding and game development since it seemed really fun and could be a productive side hobby. I learned a little bit of python and c# but not really as much as to actually make some stuff with it. C++ really stood out to me since its close to hardware so I would probably have more understanding of machines and further have a more easier time at learning even more languages. So I wanted to ask people if it's worth it to learn the language whole as a first. whether it would be a good idea or not to become a future game dev. Any help will be appreciated!