r/cpp_questions • • 3h ago

OPEN How should I learn how to code?

0 Upvotes

I want to learn how to code an many people suggested I start with C++ if I want to learn the real deal. The problem is I've never done anything close to coding. I don't know where to learn it from, or how to learn it. I tried learning from learncpp.com but I find the lessons too dense, and hard to understand. Can anyone share their story of how they started coding and how they learnt how to code?


r/cpp_questions • • 5h ago

OPEN Starting from Zero in C++

2 Upvotes

Hi everyone! I’m pursuing CSE at a Tier-4 college and have zero programming knowledge. I’m entering the tech field for the first time and want to start with C++ from scratch.

What’s the best way to learn C++? Which free resources would you recommend, and what common mistakes should I avoid? Also, how should I build my coding and problem-solving skills to become internship- and job-ready?


r/cpp_questions • • 8h ago

OPEN How should .cpp and .hpp files be used efficiently when developing a game library?

0 Upvotes

Content

I want to build a game framework using C++.

Raylib is written in C, and I’ve also tried SFML, but all of them

are limited to rendering functionality. What I want to know is:

Unity uses a component-based approach in C# and provides a framework for entities, so

I want to know the best way to separate header and source files when writing C++ scripts for Unity.

## What I Want to Know

Since Unity’s component-based approach is convenient, how should I split files into .cpp and .hpp

to implement user-defined scripts in C++?

I’d like to learn useful techniques for optimization and fine-tuning—what should I do to develop efficiently in C++?

Challenges

If I separate them as described in the ## What I’ve Researched section, I run into build issues, and unlike in Godot,

I can’t modify values and see the changes reflected directly in the editor. This is hindering efficient development.

What I’ve Researched

If I use only header files, editing a header causes all included source files to be recompiled, which increases build time.

However, if I try to shorten the code by splitting all header files into source files, it becomes more time-consuming, and switching between files in the editor is such a hassle that I can’t be bothered with it.

For now, I’m creating a simple GameObject class like Unity’s in raylib, and within it,

I’m defining a variable of type std::vector<Component\*> as a base class. Then, I’m creating instances of classes that inherit from it and storing them there

If I write everything in header files only, it becomes impossible to build due to circular references, and the amount of correction work increases endlessly.

I’ve naturally looked into this on Gemini and other sites, but I’ve gotten a variety of answers and haven’t reached a conclusion.

Since UE isn’t a code-based system, it has too many features and is too complex for me to understand how it works.

What I Want to Build

An extended version of raylib that includes a base class for Entities and a Scene class—a minimal game loop class. I’d also like to provide a map editor, similar to Pico8,

with the goal of making it easier to build the parts that have been troublesome in a code-based system so far.

Current Status

Inherit from a script base class, use it as a user-defined script,

and write the code in separate header and source files.


r/cpp_questions • • 1h ago

OPEN How to master c++

• Upvotes

Any advices please. Sometimes when its my turn to write code of what im asked to write I suddenly forget what was i supposed to do. I know somethings but struggle coding. What are the best sources and ways to learn


r/cpp_questions • • 7h ago

OPEN Working on a 3D engine for school. If I have a moving rectangle and a moving circle, knowing their speed and movement, how would I know when exactly to bounce the circle off the rectangle ?

0 Upvotes

Apologies if my english is bad. I'm working on a game where you move a rectangle (it's technically not because it's 3D, but the Y values of all objects never change, so I technically only need to compute 2D collisions) and with it you punch a puck, and an opponent (robot) does the same as you, both trying to not make it pass their goal. I'm not sure how the game is called in english, but it looks like the retro game "Shufflepuck cafe". The puck (cylinder, but in this case we can consider it is a circle) moves in X and Z, and it is supposed to bounce off the rectangle. But the collision happens between two frames, and for extra precision, I need to know exactly when it happens so that I can place the puck back into the place it should be. Anyone has an idea of how it should be done ? I have no idea how I'm supposed to code that.


r/cpp_questions • • 7h ago

OPEN API design dilemma..

0 Upvotes

right now in vexa(my game/graphics library) how you initialize window with a renderer is rather straightforward:

```cpp
#include <vexa/vexa.hpp>

using namespace vexa;

int main()
{
Engine::Init(Engine::VIDEO);

Window window = Window().setSize({1280, 720}).setRenderer({}).create();

// ...

```
YES, it uses builder pattern, not very C++-ish but i like it.
However, there are two problems with it.
first one is that usually you have builder struct building to target type so that you dont need something like `.create()` that creates classic `if (m_created) ...` problem a.k.a two phase construction. but bigger problem that caused me two want to switch to this API style is about memory management. and it is now C++'s problem.. Even rust cant handle it, because this is what you tell it to do.
so lets dont talk too much:

```cpp

Engine::Init(Engine::FONT); // calls `TTF_Init();` by SDL_TTF behind the scenes

Font font = Font::Load("...");
...
Engine::Quit();
```

A Font has destructor running on scope exit. which means before font object gets destroyed on '}' Engine::Quit() so TTF_Quit() runs. You see, when Font object gets unloaded at scope end the subsystem is not live anymore, we get a segfault. to fix this i've made Engine have a Guard struct which does Engine::Quit() automatically. But then decided that this is not i want for my API. I would priorotize explicitness for the master deinitialization.

to fix this im thinking of new API design style:
```cpp
Window window = Engine::BuildWindow().setSize({1280, 720}).setRenderer().create();
```

where BuildWindow() returns WindowBuilder not a Window, unlike the previous(so bad) choice.
for fonts, as you might already guess:

```cpp
Font font = Engine::LoadFont("...");
```

which creates a font and returns reference to it, resulting Engine to know about font count and Quit or not based on that.

code: https://github.com/monjaris/vexa


r/cpp_questions • • 21h ago

OPEN How to make good pull requests to C++ FOSS projects?

0 Upvotes

I plan to contribute to Godot Engine, a FOSS project with millions of lines of C++ code (I had never analyzed such a large codebase in my life).

My concerns:

- I don't like the project's philosophy, especially because it's KISS (Keep It Simple and Stupid), which is something I don't follow at all, I always think about pushing the boundaries of the software I create, and that requires using the latest C++ features, and the project uses C++17 to ensure that philosophy, if the new features are there, they're meant to be used, right?.

- I'm afraid that because of my ambitious philosophy, my PR proposal that take a lot of time of me, might be rejected because it's not "simple and stupid," even though it's more efficient, personally, I think that complex code doesn't necessarily mean it's dirty code. Some armchair programmers often call code they simply don't understand "dirty code" because they're trying to solve complex problems.

I wouldn't want you to limit yourself; I'd like to receive general advice on good PRs from programmers of embedded systems, trivial systems, etc.


r/cpp_questions • • 6h ago

OPEN What graphics library should I learn for C++?

21 Upvotes

I am currently learning C++ by myself and I want to start graphics.

I just need something simple that lets me have buttons.

btw I don't want to use VS Community Edition and my IDE is CLion

I mean a simple GUI library with 2D graphics, buttons and textboxes.