Questions tagged [c++]

Questions about C++, a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

Filter by
Sorted by
Tagged with
2
votes
2answers
112 views

Mixing compile time condition with runtime comditions. Bad design?

On a C++ project I got an idea to mix some compile time macro with std::optional to do something like : #include <optional> struct Foobar { std::optional<int> foo; std::optional&...
0
votes
1answer
117 views

Wrapping the UI framework

I want to write an application where I would delegate certain functionalities to 3rd party libraries. To make sure the code remains modular, I want to put these libraries behind an interface so I can ...
0
votes
1answer
104 views

Are there reasons why I shouldn't put a cpp file in my interface?

It is quite common to separate C++ code into cpp and hpp files and to define the hpp files as the interface of the code. Therefore, when you use the code as a library, you can expose the interface, ...
4
votes
0answers
82 views

Specify that a method needs a mutex held when calling

Current situation Right now I have a method like Data lookupData(Key id) { std::lock_guard<std::mutex> lock(m_mutex); auto it = m_dict.find(id); if(it == m_dict.end()) { ...
2
votes
1answer
69 views

Design for deduplicating concurrent tasks in flight simultaneously

I have 1-20 agents that issue requests over time with roughly ~50 in total in flight at any given time. Many of these requests are identical. The tasks are idempotent, but if two identical requests ...
0
votes
1answer
65 views

Run lambda inside a separate thread with a member variable caught by reference

So, I have the following two functions in THE SAME class: void start() { ... m_pRunnable = createRunnable( [spDiskManager = m_spDiskManager, path = m_path, &success =...
4
votes
1answer
412 views

The case against path expressions in #include directives

I am preparing for a discussion with my fellow programmers which will be about their use of the C/C++ #include directive. The codebase which I have to retrofit to Automotive standards is using ...
216
votes
8answers
281k views

When do you use float and when do you use double

Frequently, in my programming experience, I need to make a decision whether I should use float or double for my real numbers. Sometimes I go for float, sometimes I go for double, but really this feels ...
-1
votes
2answers
76 views

commonly used practices for deploying package primarily composed of bash scripts

I am working on a tool that primarily uses bash scripts and C++ code. Generally I have experience with basic tools written in C and C++ in which we can have a build system like ./configure; make; ...
1
vote
1answer
100 views

Unit testing, testing internals

I have a class, which uses a timer, to do some time-dependent things. Now, I do create the timer inside the class: class MyClass { public: Myclass(arg1, arg2, ...) :m_timer(new Timer(delay)) ... ...
27
votes
9answers
7k views

Is it a security vulnerability to declare class members as public?

I have always wondered whether public, protected, and private has security implications post compilation. Hypothetically: class Foo { public: int m_Foo; // Completely vulnerable and dangerous ...
1
vote
2answers
115 views

Appropriate use for the visitor design pattern

Assume I have a factory which takes in a series of bytes and outputs a pointer to a newly-created abstract message. Now, I would like to define some extensible, manageable, and clean way to "...
64
votes
10answers
11k views

Readability versus maintainability, special case of writing nested function calls

My coding style for nested function calls is the following: var result_h1 = H1(b1); var result_h2 = H2(b2); var result_g1 = G1(result_h1, result_h2); var result_g2 = G2(c1); var a = F(result_g1, ...
7
votes
2answers
9k views

Should I use a unique_ptr with an array type, or a vector?

I've been out of C++ for years, last time I used it was back in gamedesign before C++11. I see all these new pointer types which seem great. But I'm unsure when and how to use them. In the old days I ...
5
votes
2answers
316 views

Why would you use 'new' and 'delete' for something that will be referenced through a vector?

I'm going through some code from this article about ECS-systems in game programming and trying to understand it, and something I'm seeing a lot is using heap memory in places where it seems like ...
-1
votes
1answer
106 views

conversion methods: from_xxx() or to_xxx(), is there a reason I shouldn't stick with to_xxx()?

I have a C++ library that I'm converting to python. In the C++ library I have multiple constructors and many different types of conversion functions (think radians to degrees, and different types of ...
36
votes
5answers
15k views

Is there a way to use a C++ API in C#?

I want to code a little program that takes in head tracking data and moves a 3D object accordingly on the screen. To achieve this I found a software called opentrack that has a C++ API. The problem is ...
1
vote
2answers
574 views

Hiding raw pointers from public API but need to pass them internally - design review

I am designing and prototyping an ncurses C++ wrapper. It's a hobby project, nothing too serious. I will omit include guards and stdlib includes etc. Consider the following files: application.hpp #...
4
votes
1answer
315 views

Requesting information regarding the use of MUI vs. the use of GetText for i18n/L10n of Windows desktop applications

I have spent the past two days investigating which technology I will use to support translations of text strings (as part of an overall internationalization migration) for an archaic (VC6) Windows ...
2
votes
1answer
69 views

How could Vulkan pNext design be implemented in a "safer" way?

Vulkan introduces a member .pNext of type void* in all its core structs allowing to create handles. This member purpose is to allow to extend the structure by passing a pointer another one. This is ...
0
votes
1answer
55 views

Best Architecture to integrate a camera to a system [closed]

I'm trying to integrate a Camera to a more complex system in C++. The camera I'm using has a low-level API so I'm thinking about using a more simple interface. Basically what I'm planning to do is (in ...
0
votes
0answers
42 views

Is it possible to develop a web server microservice-backend with gRpc/bRpc

I've the experience of development of web servers with Go and Python. I knew that there were some web frameworks, such as Beego, Django. I have used Nginx and Beego/Django to develop and deploy some ...
0
votes
1answer
54 views

Documenting classes with doxygen (I want a birds eye view of the code but also want documentation)

When I code in plain C there is quite a beautiful interaction between headers and c files in terms of documenting the code. I tend to add the documentation on the cc files (and yes I am aware that ...
2
votes
3answers
154 views

What methods are available to implement feature flags or "loadouts" for C++ projects?

I'm looking for a system to be able to configure my C++ project to compile some sections of codes and not others depending on what target hardware I'm compiling for. The area of development is ...
3
votes
3answers
2k views

How to deal with HRESULT spaghetti?

I'm currently writing an audio application using WASAPI, which is a really great learning experience, however I have this odd problem, I don't really know what to do about all these HRESULT codes in a ...
2
votes
4answers
369 views

Confused about inheritance and correct usage. Should I avoid using members in base class?

I am using C++ , but as far as I understand most OO principles are cross language. In most of the articles that I have read and liked about inheritance the advice are about : not to use it for the ...
2
votes
5answers
1k views

On a modern compiler, how do I intentionally code for 2s complement with wraparound?

I want to compare sequence numbers (given to this code from elsewhere) that may wrap around. Simply comparing two such values will not handle the case like 0x00000002 being greater than 0xfffffffd, ...
4
votes
3answers
1k views

C++ exceptions vs. preliminary error condition checks

Preamble One of the concepts used in writing Python code is "Easier to ask for forgiveness than permission", aka EAFP. Literally, this means that instead of doing checks, whether an ...
3
votes
3answers
455 views

Best way to conditionally exclude unused code (C++03)

I'm working on a bare-metal embedded system, with a class that can be compiled for different hardware versions. The class takes in a pointer to a device and uses it, or takes in NULL if the device is ...
0
votes
1answer
73 views

Is using lambdas and overload resolution a recommended way to write a visitor for a variant?

If I have a discriminated union and want to write a function piecewise, the following code works just fine, but is taking advantage of some fairly tricky (at least to me) stuff involving overload ...
0
votes
1answer
134 views

Constantly writing a JSON file [closed]

I need to write continuously into a JSON file in C++. The format and structure are defined as requirement. The data is produced in the process itself and needs to be stored multiple times per second. ...
3
votes
4answers
266 views

Single Responsibility Principle, Inheritance

I have the following interface: class IHittable { virtual Intersections intersects(const Ray & ray) = 0 } which will be implemented by various geometric objects(Spheres, Triangles etc). Now ...
1
vote
1answer
249 views

Processing data in a cluster with multiple tasks

The goal is to provide a scaleable system implementing multiple data processing tasks which can be seen as a graph. Data objects will travel that graph. Most object will visit the same nodes in the ...
2
votes
2answers
201 views

Alternative to the Visitor Design Pattern

I have been trying to come up with a method to "serialize" various objects into various different formats. For example: class Shape { public: virtual std::string_view name() const = 0; ...
13
votes
3answers
20k views

Are Nested Static Library dependencies possible?

I am working in QT . Can a static library depend on another static library?(Static Lib is made by linking another static lib) If yes, is it possible that after linking to lib2, the generated lib(...
2
votes
1answer
129 views

Publisher-Subscriber architecture with central registry

Problem description Publisher-Subscriber architecture with a central registry where agents can either promote their capabilities or search for a given capability. The project must be developed with ...
0
votes
2answers
66 views

Deserialization and routing of objects

I know this question has to have been answered in countless ways before, but I would appreciate some help pointing me in the correct direction. I am developing an embedded system that receives "...
0
votes
0answers
26 views

User proof network app with distant database [duplicate]

I’m currently writing a software for my company (3rd world country), and I wanted it as simple as possible to install and maintain, so I started with Qt and no server app beside the database, (MariaDB ...
246
votes
11answers
27k views

Why do many exception messages not contain useful details?

It seems there is a certain amount of agreement that exception messages should contain useful details. Why is it that many common exceptions from system components do not contain useful details? A few ...
19
votes
5answers
9k views

In C/C++, should I use 'const' in parameters and local variables when possible?

This question is inspired by a question about final in java. In C/C++, should I use const whenever possible? I know there is already a related question about using const in parameters. ...
1
vote
2answers
164 views

Can you define node pointers in a base binary tree class?

I've created two separate binary tree classes, with some shared functions/variables and some that are not shared. So I have tried to abstract away the similarities in a base BinaryTree class. class ...
10
votes
4answers
8k views

How can I effectively use one file per class in C++?

Even though I have a decent bit of professional experience with object oriented programming in Java and a basic familiarity with C, I've run into a bit of a mental block with C++ that I was hoping ...
28
votes
11answers
14k views

Isn't the use of pointer variables a memory overhead?

In languages like C and C++, while using pointers to variables we need one more memory location to store that address. So isn't this a memory overhead? How is this compensated? Are pointers used in ...
1
vote
3answers
228 views

Debug statements in production quality code?

Would anyone here recommend using debug statements such as the following in production quality code? I think these are personally one of the easiest to include or exclude, but they make the code hard ...
4
votes
3answers
171 views

Should I make my class mockable by marking its methods as virtual or by creating an interface?

In the process of refactoring non-testable code we are re-designing some of ours classes so that it can be easily replaced by a stub or mock during unit tests. Here is an example of such class (...
-2
votes
3answers
90 views

Singleton as Interface for testability via dependancy injection

It can be found in many advices on topic that having Singletons is an anti-pattern. Especially for cases of testability. Can someone please advice/critique on this way (please see code below) of ...
0
votes
1answer
196 views

C++: Broadcast/observer pattern with polymorphic events

I'm currently trying to implement an event-system following a broadcast/observer scheme. I have events/notifications that contain information about what is happening: class Event { public: Event(...
16
votes
5answers
4k views

Why are C++ "complex" functions not member functions?

I was looking at the C++ library <complex>, and noticed that functions such as std::conj and std::norm are free functions i.e. static functions not placed inside the std::complex class. Why is ...
1
vote
1answer
103 views

C++ PImpl and Move Semantics

Suppose I'm writing a C++ class with the PImpl idiom for the usual reasons of providing a stable ABI and/or reducing #include dependencies. I want the class to have value semantics: modifying a copy ...
17
votes
3answers
7k views

Where to start learning to use the Boost libraries? [closed]

Boost has recently become available on the project on which I'm working, and I don't have much experience with it. The library has so many parts and features that it's hard to know where to get ...

1
2 3 4 5
52