Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
1 vote
2 answers
55 views

Global objects vs free functions C++?

I have a C++ component that contains important data that needed from various other components in my program. The component might contain its own task or not. But in either case it will also hold the ...
2 votes
0 answers
78 views

Speed up implementation of "log transform" on 2D image

I'm working on an implementation of the "log transform" operator on an image for C++, and we currently have it formulated as follows (python code). Note we use log10 instead of the natural ...
  • 129
0 votes
4 answers
122 views

Dependency injection in legacy code

I have a legacy project with many classes with high coupling, and I have a necessity to test some of them. So, I decided to introduce dependency injection principle but stumbled upon where to create ...
  • 9
0 votes
1 answer
41 views

Best practices for managing different libraries for variations of a sensor [closed]

Due to the previous supply chain issues, I currently have multiple variations of a particular sensor that performs a function in my design. Each of these variations have their own library associated ...
  • 39
-1 votes
0 answers
114 views

Is there a design with fewer similar virtual functions? [migrated]

I am writing a library using the Eigen Tensor library which makes use of templates. There is a base class called Layer from which many classes inherit from. Each child class must implement one of the ...
1 vote
3 answers
208 views

Are interchangeable types a security vulnerability? Are they good vectors for attack?

Suppose you are given a python API: def onArgumentReceived(x): doWhatever(x) # expects a unicode string I am not a security expert by any stretch of the imagination, however on the face of this, ...
  • 3,485
-3 votes
1 answer
109 views

When has C or C++ made itself intentionally backwards incompatible? [closed]

Context ( You can skip ) I will be doing a presentation on Python, and will be touching upon V3's decision to be intentionally backwards incompatible, and how that has affected Python long term. I ...
  • 3,485
0 votes
1 answer
187 views

Why exactly was the C++ convenience of not requiring a second declaration, removed?

See "Note" on second page: This convenience gave rise to serious inconsistencies and was removed several years ago The book was authored in 2003. What exactly does it mean by "...
  • 3,485
1 vote
1 answer
100 views

Conditional typedef depending on "platform"

Suppose I write a function with the following declaration: void sumAllBytes(const ByteArray& bytes); I will use Qt as an example because that's what I'm familiar with; but I am asking about the ...
1 vote
3 answers
148 views

Reading and writing with files using WinAPI in C++

This problem is quite "a classic", but I can't find a good solution to it. I am using CreateFile to open a file. Sometimes I would want it to be read-only, sometimes write-only and sometimes ...
  • 121
1 vote
1 answer
90 views

Exposing only the getters of a singleton interface in C++

I've got a file in my includes folder, which is the folder I expose, that isn't used externally and isn't supposed to be used too. When I noticed that and tried to remove it - I noticed that it's ...
  • 113
0 votes
2 answers
95 views

Low-Latency Data Sharing Between Threads in C++: Options and Considerations

What are the most efficient and low-latency approaches for sharing data between threads in a C++ system, and why? My primary concern is minimizing latency and maximizing performance, as I have two ...
7 votes
9 answers
2k views

Changing number of arguments of a function

I wanted to know the best practice(s) for ensuring scalability while passing arguments. Say, in version 1.0 of an application, the foo function looks like this void foo(int i) Now, in version 1.1, ...
2 votes
1 answer
141 views

How to avoid class-proliferation when creating a unit-testable system?

I've been working on a personal project for some time, and I believe that I'm at that point where, if I don't embrace unit tests (and ideally TDD) now, it may be too late, so I want to make the right ...
  • 29
1 vote
1 answer
169 views

Best way to type-differentiate a Point and Vector?

I'm writing a ray-tracer in C++, and while writing a constructor for the Ray class: class Ray { public: Ray(const glm::vec3& origin, const glm::vec3& direction) : o{origin}, d{direction} {} ...
  • 315
0 votes
1 answer
88 views

Should SSDP be considered as a go-to option for local network discovery in software development?

I am currently working on a Raspberry Pi based robotics project that I would like to connect to a realtime customized control panel/dashboard, mostly for debugging purposes. I created a test setup ...
0 votes
0 answers
87 views

How to show C++ concept relations in UML

A C++ concept can be constructed by combining other concepts or a list of required expressions, with boolean operators. When a class A inherits from B, there is only one relation (mostly resembles ...
0 votes
3 answers
866 views

Why is recompilation of dependent code considered bad design?

I am reading a book C++ Software Design by Klaus Iglberger. In the book, the author asserts multiple times that recompilation effects of dependent code is extremely bad. For example, The heart of the ...
0 votes
1 answer
122 views

Best software architecture approach for a single core system

Objective: Designing a data intensive application(myApp) C++ on Linux/RTOS which runs on a single core cpu, there are also 150 other applications share the same core with high priority than myApp. How ...
  • 141
3 votes
1 answer
119 views

C++ behavior as a template argument

I would like to have a class, let's say a queue, that can be specialized to its behavior. For example, let them be a SafeQueue (which disables IRQs before any access) and a FastQueue (which doesn't). ...
  • 141
-1 votes
1 answer
162 views

What does "de-MFC'ifying"a GUI app consist of? [closed]

I'm planning to port or rewrite an MFC GUI C++ app, to use in a GNU/Linux environment, and hopefully make it cross-platform. The app has few, if any, dependencies other than MFC and the standard C++ ...
  • 2,461
0 votes
0 answers
125 views

Avoiding forward declaration and circular reference in C++

Consider a card game (something like Magic or Legends of Runeterra) program, with BaseCard, Deck and GameState classes/structs. The way I've conceptualized the relationship between these classes would ...
  • 111
1 vote
3 answers
306 views

Parse 8 bytes to date time

I am trying to parse a file created by another software, but I cant identify a pattern on how this datetime is saved. There doesnt seem to be any consistency. Programming language of the software is C+...
  • 135
0 votes
0 answers
69 views

Lambdas vs scope blocks for encapsulation in c++

When working with functions that run a few short "procedures" in sequence that are not used anywhere else and it makes sense to keep it all inline, in a single function, a large part of the ...
  • 129
1 vote
2 answers
192 views

Share Global Variable in DLL, feasible or naive?

So the gist is to have a static global variable that can be modified by different executables. For example I have 2 different source files including the same dll.h: dll.h #include <iostream> ...
  • 137
1 vote
0 answers
128 views

Deployment of two programs that communicate between them

On windows, I have done one client in c++ and one server in python. In order to make the program work, I need first to run the server (in one terminal), and then I can run the client. I am trying to ...
1 vote
0 answers
68 views

Is it bad practice to specialize template method to implement strategy pattern in C++?

I came across a class that implements a kind of "strategy pattern" with a concrete implementation defined inside the main class as a template method. #include <iostream> struct ObjA { ...
  • 357
2 votes
2 answers
215 views

What is the best way to keep some constant complex data structures in a C++ code?

As implied by the title of the Q, I have a few entities and need to keep them as constant objects in a C++ project. Each entity contains very complex data structures (lists of enums, maps of maps, etc....
0 votes
1 answer
108 views

Reducing contention/locking in a job system involving read/write dependencies?

I have a job system that has two different types of dependencies per-job: Jobs can rely on other jobs to be completed first, but this is optional Jobs have read/write dependencies (shared/exclusive) ...
-2 votes
1 answer
315 views

What is the use of Multiple Inheritance in languages like C++ and Python?

C++ and Python are the only two languages I know supporting multiple Inheritance. Other object oriented languages I have seen like Java and Ruby do not support multiple inheritance. Even the front-end ...
0 votes
2 answers
138 views

std::string_view and std::string in utility library interface

We have several medium to large software projects targeting different platforms (arm32/64 and x86/amd64 on Linux and Windows) with a lot of duplicated code in them, since every project has its own ...
0 votes
3 answers
404 views

Is it possible to instantiate a template class at runtime?

Suppose I have two abstract classes called Color and Animal And I can create classes Green/Red/Blue derived from Color and classes Dog/Cat/Pig derived from Animal at runtime using factory pattern. ...
0 votes
3 answers
329 views

Optimizing a string to enum converter [closed]

I have built a string to enum converter, which converts a known set of strings that it receives into enum, in order to satisfy a function pointer. Some of you may recognize some elements of this ...
3 votes
5 answers
2k views

Alternatives to if-else on data reading

I have some code on Arduino (so, written in C++) that receives a String through the UART terminal, reads the String, then decides what String to print back and how many things to print depending on ...
1 vote
2 answers
239 views

Is it bad code design to use an out of scope static variable?

I have a function that uses a static variable to count how many times it got called: void func () { static int counter=0; counter++; /* some code */ } The code in the function executes ...
  • 121
-3 votes
1 answer
122 views

What is the importance of "this" pointer in cpp? [closed]

I apologize for asking this intuitive question. I'm not good at programming and my recent work requires me to work a lot with SDEs. I wonder what might be the advantages using the this pointer? I ...
  • 15
3 votes
2 answers
638 views

When should one utilize Atomic Operations?

I have never used atomic operations, and remain largely ignorant of how to utilize them. And yet, I often come across objects like this when peering into Qt's backend: https://doc.qt.io/qt-6/...
  • 3,485
3 votes
1 answer
133 views

const correctness re: reference members

tl;dr is is a good idea for const methods to be able to mutate objects referenced as reference members? Imagine you have some kind of work queue that uses items that look like so: class Consumable { /...
2 votes
2 answers
280 views

In what language does a method not return a value and a function does?

I don't know from where I got this but in my head a function returns a value and a method does not. I know that with OOP a method is a function related to a class. But I am trying to remember where I ...
0 votes
1 answer
111 views

Design of A Multithreaded Simulator

When designing my simulator, I have gotten stuck on 2 main design choices. The simulator can be described as having X number of nodes (between 50 - 2000) that each need to independently do some ...
1 vote
3 answers
196 views

Class design: should I split responsibilities or should the class take care of itself?

I have a Curve class that has some CurveData inside as private member as well as getter functions for topics of interest (e.g. peaks, width and so). So the math logic of a curve is inside this class. ...
0 votes
0 answers
55 views

Avoid double allocations when wrapping a class that requires to be created as a shared_ptr

I'm using mqtt_cpp as a mqtt client in my applications. But because I want to limit the api that is provided by mqtt_cpp and adapt it to my needs I came up with the idea of wrapping this class into my ...
  • 275
0 votes
1 answer
98 views

What information should one infer from a class header that marks its constructor explicit?

If a class is written well, you should be able to gleam all relevant information about the class simply by looking at its header. If one sees that the constructor is marked explicit: What should one ...
  • 3,485
1 vote
3 answers
472 views

Should I use the "die" idiom in C++?

If we implement the following function: template <typename... Ts> [[noreturn]] inline bool die(std::string_view message_format = "", Ts&&... args); We can then write: if (...
  • 2,461
1 vote
1 answer
134 views

C++20, specialize struct once per type and allow member functions to take type as reference, raw, std::unique|shared_ptr or any other smart ptr

Situation I have some existing functions which expect containers which can be iterated and which have certain value_type. The value_type can be a value or some (smart) pointer. All the value_type have ...
2 votes
0 answers
468 views

Best way to store key-value pairs of different types in c++?

I'm reading values from a (PE) binary file. The values have a known length and position in the file and are stored with no padding (right next to each other). They store various types (int, long, ...
  • 121
-3 votes
1 answer
101 views

How would a SRP `class Car` look like? [closed]

SRP insists that a class should have only a single a reason to change. Please guide me through the following example. class Car { drive_forward(); embark(); disembark(); fuel_up(); } ...
  • 6,985
0 votes
1 answer
357 views

is there a two-way (bidirectional) observer pattern?

I have two classes. "System" and "Bluetooth". I want to have a really loose coherency between these two classes as they should be able to exist or not without depending on each ...
0 votes
3 answers
237 views

Use aggregation like LSP in C++

I was reading about LSP (Liskov Substitution Principle) in a book called Clean Architecture: A Craftsman's Guide to Software Structure and Design. I have a question regarding how this would be ...
-1 votes
2 answers
155 views

Performance hit after non-functional refactoring

I was asked to refactor some C++ code recently for the purposes of increasing unit testing coverage. The problem was that the code was tightly coupled on one compilation unit, so we had the equivalent ...

1
2 3 4 5
54