Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c++]

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

0
votes
1answer
51 views

C++11 freeRTOS questions about queue usage and object design

Background I'm writing C++ firmware with freertos to penplottingrobot. It's a makeblock XYplotter and the firmware is connecting to mDraw software for command instructions thru USB drivers. MDraw ...
16
votes
4answers
950 views

continuous integration for scientific software

I'm no software engineer. I'm a phd student in the field of geoscience. Almost two years ago I started programming a scientific software. I never used continuous integration (CI), mainly because at ...
0
votes
1answer
58 views

How to write a database management library to interop with C++ and Python? [closed]

We have a C++ application (.NET GUI) that outputs a lot of runtime data. We're building a Python app to crunch and display all of this data. Right now, we're trying to determine the best way to manage ...
2
votes
0answers
60 views

Dynamically load user code from a common library

My project aims to provide a common interface between multiple different HDL simulators, so users can write test benches that will work no matter the simulator used. In this situation, it is the ...
2
votes
2answers
200 views

Is the meaning of `const` still thread-safe in C++11?

I recently came across Herb Sutter's video from about how the meaning of const and mutable has changed in C++11 to mean bitwise const (and thread-safe, as a consequence) instead of the traditional ...
0
votes
2answers
88 views

Design a tree-like hierarchy of ownership classes

I have a class, call it App, that will instantiate and own a set of classes of type Agents, each of which will instantiate and own a set of Listeners. Ownership is unique and non-transferable, hence ...
2
votes
3answers
212 views

Why is the Command desing pattern useful for game AI?

I'm trying to learn the Command design pattern and apply it to the game I'm working on. First I read about the general implementation, and I feel like I understand it pretty well. Now I want to know ...
0
votes
1answer
78 views

Orchestrating Object Instantiation and Intercommunication

We have a C++ project managed by UML software, which generates code for instantiating and passing data between objects. Unfortunately, this software adds a lot of overhead to our builds and ...
2
votes
2answers
73 views

Separate variable value from error code using struct

Let's say I have a function that calculates a sensor output, all values are >=0, but also I have to detect some error situations like "NO_POWER" which I encoded with value "-65500". On my application ...
0
votes
0answers
37 views

Start a timer based on a different event firing

So I have a design issue I cannot seem to figure out how to do, my situation is as follows: I have multiple array of timers, one of which should be reset when the corresponding key, and then a ...
0
votes
0answers
52 views

What would be the downsides of creating a derived interface of interface?

Would there be any downsides of creating sub-interfaces for virtual member functions that have different parameter types? A drawing of this is shown in the image attached. Apple and Orange do not ...
3
votes
0answers
73 views

Optionally runtime properties

I’m looking for information on a pattern that I have used recently. The basic idea is that there is a type with a property that can either be compile-time (template parameter) or runtime (member). std:...
-1
votes
0answers
20 views

How to use use third party Apache APR library in my CMAKE project

I got CMAKE project that use Apache APR library. For now i got generated dll on windows and build from them. But now i want to compile my project on linux(ubuntu) or compile with my project the apr ...
12
votes
3answers
496 views

Is using C/C++ macros as a shortcut for conditional compilation a good practice?

Let's say I want to have several types of output messages in my code. One of them is DEBUG, which is printed only, when the code is compiled in Debug mode. Usually I'd have to write something like #...
0
votes
0answers
56 views

Multiple nested struct having variable types : encoding and decoding

I am working on a client-server application. I have message structs which need to encoded (serialization) to a char buffer before sending it over the network. The structures are highly nested. For ...
0
votes
1answer
184 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 #...
1
vote
1answer
82 views

An interface for designing Arduino code

Often I want Arduino board to control several peripherals. Writing program for all of them in one document using #define SOME_PIN 4 constructions seems pretty inconvenient to me. Especially in such a ...
-3
votes
1answer
48 views

QElapsedTimer hasExpired() - Is it one msec off?

Here is a a part of the documentation of Qt's QElapsedTimer: bool QElapsedTimer::hasExpired(qint64 timeout) const Returns true if this QElapsedTimer has already expired by timeout milliseconds (...
1
vote
3answers
225 views

Do any compilers do this optimization for virtual calls?

This just came to mind, and not really sure how to search for this. Let's say you have the following classes class A { public: virtual Foo() = 0; virtual ManyFoo(int N) { for (...
2
votes
3answers
378 views

Is inlining almost all of my C++ application's methods a good or bad idea?

I am used to D coding and Python where the class definition also contains each method definiton. So it is my preferred style of coding. I abhor having to switch to the .cpp file and use that long ...
1
vote
2answers
142 views

How can I avoid redundant object properties when using a database?

I am writing applications in C++ using an sqlite database. Suppose I have a simple user system with a user database. User Class class User { private: void LoadFromDatabase(uint32_t id); ...
0
votes
1answer
59 views

API DESIGN: Store Table of function pointers in client or dynamically in api service

FIRST AND FOREMOST: Forgive me if the following question falls into the "off topic" category of this StackExchange, due to its slightly opinion polling nature. This is not my intention, I am simply ...
0
votes
0answers
93 views

How can I gracefully handle this addition of animation?

I have the following setup in a GUI library I'm making (for fun). Ignore the colors and positions being integers, it's just to serve the purpose of illustration. // Example program #include <...
0
votes
5answers
183 views

Optimization of iterative loop with removed items

I am translating a piece of software from an old language to c++ and am currently in the optimization stage. The software performs a calculation of loads for several items in a number of timesteps, ...
3
votes
3answers
168 views

Abstract Parent and Inheritance vs. Strategy Pattern and Composition

I'm currently refactoring a class that looks (after some refactoring and very much simplified) somewhat like this: class Foo { public: Foo(bool someFlag) : m_flag(someFlag) { }; void ...
0
votes
0answers
54 views

c++ templates - combining deduction with default template arguments

I have a simple class (details here) namespace MemoizerSupport { template <typename T1, typename T2> using DEFAULT_CACHE = LRUCache<T1, T2>; } template <typename RESULT, ...
0
votes
1answer
122 views

How would you design a “multithreaded” LRU cache using C++ (unordered_map and Linkedlist)?

Please note that this is about a thread-safe LRU cache (not simply a LRU cache as specified in https://leetcode.com/problems/lru-cache/description/). It isn't a duplicate of LRU cache design question ...
15
votes
2answers
3k views

Is converting a C++ method to a C function with a pointer argument an acceptable pattern?

I use C++ on ESP-32. When registering a timer I have to do this: timer_args.callback = reinterpret_cast<esp_timer_cb_t>(&SoundMixer::soundCallback); timer_args.arg = this; Here the timer ...
0
votes
3answers
365 views

Avoiding vtable pointers in objects in C++

In my previous question, it was highlight that implementations of C++ such as GCC must store a vtable pointer in every copy of a class for each parent class which has a virtual function. So a class ...
0
votes
0answers
135 views

Using Boost coroutines directly in C++

I have an event-based program I would like to re-write to use coroutines. Currently there are a large number of normally suspended threads which each send events to a common event queue for task ...
0
votes
3answers
129 views

Implementing interface using class members

This was just a question I was wondering about in terms of best practice. I am writing a small C++ program that uses an interface to implement a function. In the class that uses the interface (i.e. ...
1
vote
1answer
159 views

Organizing Source files/classes in big projects in C++

I'm currently writing a bigger program in C++ and have reached a point were I get problems with the organization. I wonder if namespaces are a way out. I will try to explain what the program does and ...
1
vote
1answer
145 views

Remove duplicated switch statements caused by not knowing type at compile time of opencv matrix?

I have a situation that occurs 5 times in my code, and continues to grow. Basically I have the same switch statement structure every time I need to perform an operation that involves my matrix and ...
2
votes
3answers
96 views

How do I put objects of different types derived from a common base in the same array? [closed]

I have two classes called Player and Enemy both inheriting from a class called GameObject, how do I store them both in an array of type GameObject while still keeping their own unique information? I ...
1
vote
0answers
90 views

3D Rendering Engine architecture for multipass rendering

I'm implementing a simple 3D rendering engine for my game, I'm using DirectX11. I created a simple architecture for the rendering engine, with a central rendering system (RenderingSystem class, a ...
1
vote
6answers
329 views

Is it okay to have a parent class that doesn't represent an entity and doesn't have an “Is-A” relationship with its child classes?

I want to have an array that can hold elements of many classes data types, and each of these classes have a method called printInfo(). The way I can do that is by having a parent class called ...
-1
votes
1answer
46 views

Best OOP practices for object accessing “aggregate object” members?

Is there a best practice for something like this? (Example in C++) class A { public: int usefulParameter; std::vector<B*> bContainer; }; class B { public: void ...
1
vote
2answers
223 views

Calling a static method from constructor's member initializer list

I'm implementing a simple rendering system for a game engine. In my engine I have renderable entities that have a Model component (I'm using inheritance as opposed to a ECS for my engine for now, but ...
4
votes
4answers
154 views

Designing for 3rd Party Extensibility

I'm having trouble understanding how to provide an API to 3rd parties in order to allow extensions for desktop applications. I understand that if I'm using a compiled language (e.g. C++), I can load ...
3
votes
4answers
190 views

C++ Preferred method of dealing with implementation for large templates

Typically when declaring a C++ class, it is best practice to put only the declaration in the header file and put the implementation in a source file. However, it seems that this design model does not ...
0
votes
1answer
54 views

Abstract data communication in modular design

I'm doing the analysis for a software which I've had in mind for a long time. Its purpose is to turn sound into an image, apply graphical transformations on it, and turn it back into sound to hear the ...
25
votes
2answers
3k views

Implementation of pure abstract classes and interfaces

Although this isn't mandatory in the C++ standard, it seems the way GCC for example, implements parent classes, including pure abstract ones, is by including a pointer to the v-table for that abstract ...
0
votes
1answer
106 views

Can source code, automake and configure files for multiple OS co-exist in one Git branch

I am working on an open source project that should be compiled for multiple operating systems including Ubuntu and Windows. I am working on how to structure the Git repositories and branches for ...
1
vote
0answers
25 views

Applying an overloaded/templated function depending on the type of a QVariant

I'm trying to take a QVariant (in this case from a QProperty generated on a class) and based on the type, return a QWidget that allows for it to be edited appropriately. a signature for the ...
-3
votes
1answer
98 views

Enforce that all dervied classes and subclasses always define a member function

How to do I enforce that all classes that have class A as base define EveryClassHasThis()? Class A { public: virtual void EveryClassHasThis() = 0; } For example in the below simple case; how to ...
1
vote
2answers
152 views

Using C coding conventions in C++ code [duplicate]

I'm working on a large codebase whose core modules are in C and extension modules are in C++. We have a coding convention for C code but I'm being told that we need to enforce the same coding ...
-1
votes
1answer
89 views

Combining the arguments of a function using a single structure

What are the consequences (pros and cons) of using a single structure as the argument, instead of a list of parameters. Some of the advantages I see are: create multiple default parameters. Need not ...
1
vote
2answers
390 views

How to deal with exceptions in DLLs?

I recently started working on an existing project written in C++ Builder. The application consists of a MainModule that loads LOTS of modules (DLLs). The MainModule itself is a DLL (there is a small ...
2
votes
0answers
75 views

Creating bindable input handler in C++ spanning two separate modules

I have a wxWidgets application. This is the first, main module. The second module is an openGL engine. It's a model-view-(controller) structure, where application is the view (and the controller), ...
1
vote
2answers
276 views

How is usually named a non-const getter?

Quite often you need to define a getter returning a reference to a member, and a corresponding setter. They usually look somewhat like this : class Foo { Type member; public: const Type& ...