Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
729 views

Some approach or Design Pattern to implement same method different parameters of Interface class

I am using the Flyweight pattern to cache and reuse objects of the different classes. For example, I have a Shape interface class and multiple types of Shapes implementing the methods from the ...
Himanshuman's user avatar
0 votes
3 answers
472 views

Mapping a range of values to a single value

So I have this problem where a specific ValuesA enum value is to be mapped to a respective ValuesB enum value, The trick is there can be multiple ValuesA mapping to a single ValuesB enum. So for the ...
xyf's user avatar
  • 109
2 votes
1 answer
105 views

Converting the classes with multiple dimension to Bridge design pattern

Bridge design pattern is something which is very confusing and GOF does not do justice with beginners in the definition. I was asked in my current organisation to add one more dimension to our class ...
Himanshuman's user avatar
-1 votes
1 answer
270 views

What is the best way to store a recursive data structure? [closed]

What is the best way to store a recursive data structure in a program? (in C++) I'm reading data from file, and want to keep it in memory while I validate the data and the user can manipulate it. It ...
masher's user avatar
  • 107
2 votes
3 answers
349 views

Why do we need factories in the first place?

I went through various blogs but nowhere I can find the reason of having virtual constructors in C++. Why is virtual constructor needed and lets say if we go through the wrong way of creating virtual ...
H Kumar's user avatar
  • 31
0 votes
0 answers
40 views

Binding delegates from owner vs in component to prevent coupling

While researching the topic of Coupling, I still have a little misunderstanding about what counts as less / more Coupling. I will take as an example two options for setting delegates in Unreal Engine ...
scydev's user avatar
  • 1
5 votes
1 answer
182 views

Is tag dispatch as used in CppCoreGuidelines T.65 antiquated?

The CppCoreGuidelines contain the following: T.65: Use tag dispatch to provide alternative implementations of a function [...] Example struct pod_tag {}; struct non_pod_tag {}; template<class T&...
Jan Schultke's user avatar
4 votes
9 answers
846 views

Can a Domain Object always be "completely ignorant of persistence" and yet still possible to persist?

Domain Object, while not necessarily a design pattern, can at least be considered as a design "concept", and one of its points is: https://wiki.c2.com/?DomainObject Domain objects should ...
The_Sympathizer's user avatar
1 vote
1 answer
166 views

Is it more secure to develop libraries in-house than using existing libraries? [closed]

I (unfortunately) work in a large German corporation, in a department where the codebase is up to 20 years old, written in C++ (actually more like C with the occasional classes, since most developers ...
hyperbole's user avatar
2 votes
3 answers
874 views

C++ Is it okay to use nested classes as a way to namespace derived classes?

I have many abstract classes that describe many abstract ideas and objects. These classes have many complex relationships with each other, and I realize that while writing code with some of the ...
nreh's user avatar
  • 151
2 votes
1 answer
134 views

Functions vs Classes for delegate pattern

Please consider the following sample #include <cstdio> #include <functional> #include <memory> #include <utility> class PaintDelegate { public: virtual ~...
Zoso's user avatar
  • 241
0 votes
0 answers
60 views

Decoupling a Configuration API in an Embedded Framework

In my embedded project I am designing a framework that allows the user to create widgets at compile time. All widgets must provide the same base functionality. Further, there are multiple widget ...
nowhere_'s user avatar
9 votes
4 answers
3k views

How to analyze and understand the use/application of a "class" in a colossal million-line legacy code base?

I am working on a huge code base (more than a million lines of code with a sophisticated architecture) written in C++ over the span of a couple of decades. The task on which I'm working at this point ...
Dude's user avatar
  • 207
-1 votes
1 answer
135 views

Best approach to communicate C++/Python and Front-End

I work with Computer Vision applications, mainly in Python and C++. Recently, I get involved with a customer that wants to create a UI based on React JS to visualize the results of our software in ...
mbenencase's user avatar
12 votes
4 answers
3k views

How to initialize the same global resources from multiple modules independently?

I encountered the following situation: I have two modules, TokenService and Wifi which are initialized from main(). The modules themselves don't know of the existence of each other and function ...
glades's user avatar
  • 377
-2 votes
1 answer
364 views

How to create a cross-platform class abstraction?

I have been struggling with how to create an "object-oriented" cross-platform abstraction. In C++, a class requires a certain amount of coupling between its interface (i.e., public methods) ...
Patrick Wright's user avatar
0 votes
2 answers
244 views

What is the difference between C++ Composite and Chain of Responsibility patterns?

A Composite delegates calculations of unknown depth to a virtual method. A Chain of Responsibility passes events to an arbitrary deep line of handlers. Sounds the same to me. What am I missing?
Vorac's user avatar
  • 7,119
2 votes
1 answer
200 views

Socket Class Design C++

I am currently trying to design some C++ classes that encapsulate POSIX sockets and their relevant functions. I want to try and design classes that are simple, elegant, and make the best use of design ...
nick2225's user avatar
  • 147
2 votes
1 answer
836 views

Saving and reading files in user specific application data in C or C++

Most useful or reasonably complex applications need to save data such as user settings or saved games or browser history. I have been working on applications and games in C or C++ but I am not sure ...
user16217248's user avatar
  • 1,167
3 votes
3 answers
324 views

How to efficiently build objects without default constructors

I am trying to explain and understand a way to create object which cannot have "default" instances. Typically I want classes which represent, as closely as possible, the real-life concept I ...
Patrick Wright's user avatar
0 votes
1 answer
471 views

C++ wrapper around raw array - memory management

I have simple wrapper class around C-style array. I don't want to use std::vector since I want to have only one array even if I do copy of the struct. With std::vector the vector is also copied. ...
Martin Perry's user avatar
1 vote
0 answers
90 views

What is the best way to implement the following type of paradigm?

I have the following piece of code. Line 1 is a container (for simplicity, one can think of it as a list of elements e1, e2, ..., en). Now there is a function function_fun which takes as input an ...
A J's user avatar
  • 19
-2 votes
1 answer
94 views

Support different versions of a third-party library for different OS

how to support to vendor libraries. Apart from file changes, and APIs, the new version is 64 bit whereas the old is 32 bit What's the best design and implementation effort to support two version of a ...
kroger9's user avatar
  • 15
0 votes
1 answer
119 views

Use PGO (profile guided optimization) to determine optimal value of variables in code

Reading this interesting paper it seems that a lot of performance loss is due to scheduling overhead in tight loops. To recap: There's a variable called "Chunksize" which determines how big ...
glades's user avatar
  • 377
-3 votes
1 answer
193 views

Will anything that's written in c/c++ be rerwritten in rust? [closed]

Will anything that's written in c/c++ be rerwritten in rust? for maintainance, even for performance?
Snowmanzzz's user avatar
0 votes
1 answer
161 views

Sink or non-sink API's?

This might be an opinionated question but I'm eager to hear your anecdotes as I'm at the beginning of designing a new API. Now I'm questioning whether I want this API to be a sink API or non-sink API. ...
glades's user avatar
  • 377
-1 votes
1 answer
94 views

How to handle dependencies between objects/components

Im currently working on a college project on the simulation of magnetic interactions of particles, see physical simulation: design thoughts. Right now im starting to code my system according to this ...
Meck3l's user avatar
  • 17
0 votes
1 answer
198 views

Clang compiler is unstable for me, backtrace msg asks me to open a GitHub issue. How often should I post my issue?

This question is about how to be a good citizen in an open source community, and do my part to effectively participate, to advance the project/not harass people. I am building a medium-sized C++ ...
cs-'s user avatar
  • 111
0 votes
1 answer
387 views

Custom #pragma directives

I'm creating a language parser on a microprocessor in C++. For the tables of keywords and commands, rather than maintaining a single curated file (alphabetically sorted, etc), I'd prefer to declare ...
SteveG's user avatar
  • 33
4 votes
5 answers
737 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 ...
SomethingBetter's user avatar
2 votes
0 answers
177 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 ...
kwsp's user avatar
  • 129
0 votes
4 answers
400 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 ...
Ruslan's user avatar
  • 9
0 votes
1 answer
70 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 ...
Rico's user avatar
  • 39
1 vote
3 answers
258 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, ...
Anon's user avatar
  • 3,593
-3 votes
1 answer
199 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 ...
Anon's user avatar
  • 3,593
0 votes
1 answer
259 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 "...
Anon's user avatar
  • 3,593
0 votes
1 answer
234 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 ...
Patrick Wright's user avatar
1 vote
3 answers
315 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 ...
EL_9's user avatar
  • 121
0 votes
1 answer
220 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 ...
RedYoel's user avatar
  • 123
0 votes
2 answers
577 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 ...
dogma sucks's user avatar
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, ...
awakened's user avatar
2 votes
1 answer
239 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 ...
Pablo's user avatar
  • 29
2 votes
1 answer
278 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} {} ...
SRSR333's user avatar
  • 325
0 votes
1 answer
317 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 ...
Stathis91's user avatar
1 vote
3 answers
1k 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 ...
User 10482's user avatar
0 votes
1 answer
139 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 ...
uss's user avatar
  • 141
2 votes
1 answer
223 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). ...
JD.'s user avatar
  • 131
-1 votes
1 answer
222 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++ ...
einpoklum's user avatar
  • 2,496
1 vote
0 answers
377 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 ...
Janilson's user avatar
  • 121
1 vote
3 answers
948 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+...
rosi97's user avatar
  • 135

1
2
3 4 5
55