Stack Exchange Network

Stack Exchange network consists of 175 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
0answers
9 views

FTT audio processing for an audio spectrum audio spectrum [on hold]

I want to make a fast and responsive audio visualizer (in real time). I want to use the GPU for the Fast Fourier Transform because almost everyone that has Steam installed has an APU/GPU with ...
0
votes
1answer
15 views

How do I create a ribbon desktop application in C++ in Visual Studio? [on hold]

I want to use Visual Studio and want to create a C++ Desktop Application with the Ribbon UI, but everywhere I look, I can't find a solution that would help me get started or I must have missed ...
2
votes
1answer
53 views

Design Review Of SOLID Principles For An Autonomous Mobile Robot

I am self-learning robotics, C++ and good object oriented design. I have asked various questions over the past couple of weeks: 1 and 2 that have lead to the following design. The design goal is for ...
2
votes
1answer
136 views

Would de-coupling using interfaces/templates make the system easier to maintain at the cost of over-engineering?

I have been practicing this hybrid approach for dependency injection in the last couple of days and I am wondering if it should also apply to components which are within the same package? For example:...
0
votes
1answer
108 views

How can I vary the distance function in my code?

I have a simple design question. I have a tree based C++ class. It needs to use a distance function in order to calculate nearest neighbors. But the distance function is available from an external ...
5
votes
1answer
241 views

Is it better to use lambda functions or boolean variables to record state

I have heard some people claiming that boolean state variables are generally bad and should be avoided when possible. Apparently in many cases it is possible to put state into lambda functions, ...
2
votes
1answer
62 views

different collision geometries in a component based game engine

I'm writing a simple game engine and after a lot of rethinking/refactoring I settled with sort of a component based architecture (not strictly ECS, but it isn't inheritance based anymore either). So ...
1
vote
4answers
191 views

Should I always use iterators when working with strings?

Here is the known old way to iterate over the string: for (int i = 0; i < str.length(); i++) { char c = str[i]; } However recently I have also seen in multiple places the usage of ...
2
votes
1answer
91 views

Design approach for extending class functionality - Embedded C++

For my company i am refactoring our embedded C/C++ code base to increase re-usability for commonly used functionality. Currently i am refactoring our command line interface but i ran into a design ...
2
votes
2answers
151 views

Should smart pointers be exposed in a C++ API?

Exactly as the name says, should smart pointers be exposed in a C++ library API? I've used quite a few C++ libraries and haven't ran into exposed smart pointers yet. Given that it's very common to ...
2
votes
2answers
209 views

What is the difference between a static library and an archive library?

In the comments of a recent answer, I equated a static library with an archive of compiled object files. The response was that they are not the same, so what is the difference? To clarify - gcc ...
-2
votes
1answer
114 views

How to obtain and store a subgraph of a graph in C++?

I have implemented a graph structure (for graphs having ~30,000 nodes and ~300,000 edges) as follows: class graph; class node; class edge; class graph { public: graph(){}; vector<node*> ...
0
votes
1answer
94 views

Network programming (boost::asio), architecture and communication protocols

I'm trying to make a simple network application using boost::asio. I think that I understood the basic things like io_context, async functions etc, but I really don't know how to deal with buffers. ...
1
vote
1answer
67 views

Library with different runtime behaviour based on usage history (design question) [closed]

I want to design a hash table library that keeps usage statistics and based on how it is used will use different implementations at runtime. For example use a certain implementation for small size ...
5
votes
1answer
176 views

What is the best way to handle glue between different classicly OOP objects at the higher levels of abstraction?

In object oriented programming, it is commonly said that each class/object/instance should have a well-defined purpose. For example, there may be a Window class in a windowing toolkit, a ChunkLoader ...
4
votes
3answers
274 views

How to reach the parent object?

I have a parent object that has some other objects as fields. The parent object fully owns these fields: they can be declared as fields of the parent object (MyPart part), directly, not as references. ...
5
votes
1answer
225 views

Is there any reason *not* to forward declare all forward declarable function parameter/return types?

I ran into a situation where my build speeds have started to become large and have affected productivity. I had already minimized header dependencies before using forward declarations. Now I've ...
2
votes
1answer
112 views

How to write a class that uses other classes but needs the same functionality - should I just wrap around the methods?

I want to create a class ProcessHandler for Windows that pretty much uses the WINAPI. The class ProcessHandler should be able to scan memory, emulate keyboard and mouse, needs some DLLInjector, some ...
1
vote
1answer
109 views

What is the best way to handle the scenario in C++ where there are two methods that are identical, except one is const?

I am currently working on a program in which I encountered an issue (not for the first time) where I have two acessor methods for a data structure. The methods are identical, except one is const and ...
7
votes
0answers
222 views

Securely sandboxing user scripts in a C++ program

I've been working on a personal project in C# whose purpose is more or less to allow the user to execute scripts written by other users and restrict the permissions of that script. My program compiles ...
2
votes
1answer
149 views

Approach for implementing Device and Protocol layers in C++?

I'm writing a program that will interface with an external device. It will support numerous devices that may use different communication interfaces like USB, serial, etc. This is what I have so far: ...
5
votes
2answers
157 views

Help with dependency inversion

I'm learning about Binary Trees in school and I'm trying to apply the SOLID principles to it. My problem is in my BinaryTree::insert() method I'm creating a new BinaryNode, and from what I've ...
5
votes
1answer
114 views

Working with “external” object IDs

I have often encountered a situation in which users of a program (not necessarily human, just an external agent) need to be able to reference objects of a class with a certain "external" identifier, ...
-1
votes
1answer
84 views

Wait and wake-up vs. start and join for multithreading

A function that is repeatedly called should do multiple tasks: request a vector from a server. calculate a new vector. send this latter to a server. append the new vector summed to the downloaded one ...
-2
votes
2answers
127 views

How to handle multiple versions of binary file format

I'm writing a reader for the custom binary file format used in one game. The format has multiple versions for example: struct FileHeader { ushort version; uint fieldX; // version 1 uint ...
0
votes
1answer
108 views

Class holding collection of other class

I have a class Item. Then another class ItemCollection holds std::map<int,Item> item_collection_. The reason to create the class ItemCollection is if I want to do something with collection of ...
0
votes
1answer
94 views

Streamlining development process of Linux C++ CLI app [closed]

On Linux Mint 19 with C++ compiler version: g++-8 (...) 8.2.0 I am compiling and running my project named: getPixelColor Using a shell script: #!/bin/sh g++-8 -std=c++17 -Wall -Wextra -Werror -...
1
vote
3answers
224 views

What is late binding?

I know, there are lots of sources on the internet, but I do not understand them. Wikipedia: "Late binding, dynamic binding, or dynamic linkage is a computer programming mechanism in which the method ...
1
vote
2answers
202 views

Splitting a critical application into multiple executables

We're developing some C++ application that analyses strings using some data. The data is large (a few gigabytes) and takes a significant amount of time to load into memory, and timing, as well as ...
-2
votes
1answer
95 views

What's the best design pattern approach for introducing optional feature to current code base?

I had a class hierarchy with several classes that interact with each other. After introducing new feature that is optional (but it depends on external libraries) I have the following code (just ...
1
vote
0answers
172 views

Designing a multithreaded TCP/UDP server for audio sharing

As briefly introduced in the question title, I am trying to design and implement a server application able to let clients share audio contents between themselves. In order to achieve that, I decided ...
-3
votes
1answer
144 views

Which is the best pattern or solution for this problem?

Given the following class: class S { ... private: void Action1(); void Action2(); . . . void ActionN(); } The Action functions are related, which are called in ...
1
vote
1answer
200 views

Unit testing abstract classes with Google mock (gmock/gtest) (C++)

I want to test an abstract class with: Pure virtual methods that should be overridden in sub-classes Non-pure virtual methods that use the pure virtual methods (as opposed to this question) class Fu ...
-2
votes
1answer
62 views

Using static member methods to check for object being NULL

Is it a good practice to use the static member methods to check if an object of a class is NULL or not. The object would be sent through the parameters offcourse. Something like, #include <...
5
votes
1answer
403 views

How common are destructors in modern c++ code?

In the standard c++ library, all containers and all input/output streams have their own constructors and destructors, that handle all the relevant resource acquisition and release. So for most tasks ...
0
votes
0answers
86 views

Base class with bool flag to imitate virtual constructor

I am using bool flag to call base class function when needed to imitate virtual constructor. I am using this way for inheritance purpose. I have a Base class constructor with int and bool. The bool ...
6
votes
1answer
224 views

How can I reduce the amount of storage needed for a gravitational n-body simulation?

I am currently attempting to create a gravitational n-body simulation using a modified Barnes-Hut algorithm, to be more amicable to GPU computation. This is primarily as a learning project. My goal is ...
1
vote
0answers
204 views

Unit testing C++ in XCode

I'm working on a plugin for some drafting software. The plugin takes the form of a dynamically loaded mach-o bundle. The software vendor provides a template plugin in the form of an XCode project. ...
1
vote
1answer
109 views

One process using std::thread, 2 physical CPUs, 4 cores each, parallelism level?

Suppose I have a one C++ process, and I want this process to run eight threads in parallel. And suppose that: I have a computer with two (2) physical CPUs. Each CPU has four (4) cores, so that's 4x2 ...
3
votes
3answers
241 views

In c++, is there a way inside a function block, to execute cleanup code after the value has been returned?

Backstory (You can skip) I am building an API for managing Files and Directories in a consistent manner across a project. This is for deduplication and consistency when performing a task, and in this ...
0
votes
1answer
63 views

Avoid numerous dynamic_cast_ptr in the API design of polymorphic types

I am trying to design a geometric intersection API. Below is the code to represent geometric elements. #include <iostream> #include <memory> // Since I did not write the Shape class I ...
8
votes
4answers
532 views

C++ Iterator, Why is there no Iterator base class all iterators inherit from

I am learning for an exam and I have a question which I am struggling to give and answer for. Why does no iterator base class exist all other iterators inherit from? My guess my teacher is ...
0
votes
1answer
102 views

Difference between a strongly typed language and a weakly typed language with type annotations from the developer's point of view?

I understand that there are major technical differences between how a strongly typed language is compiled and how a type annotated language is compiled/transpiled. But as a developer writing in a ...
1
vote
2answers
102 views

Pattern for composing streaming operations without threads?

I'm working on a library that lets me write operation on an input "stream" of data (I don't call them that, but it's a potentially unbounded input regardless, think data coming from a socket). I ...
1
vote
2answers
256 views

Why is the whole Hadoop ecosystem written in Java?

Developing Big Data processing pipelines and storage, you probably come across software which is more or less a part of the Hadoop ecosystem. Be it Hadoop itself, Spark/Flink, HBase, Kafka, Accumulo, ...
0
votes
4answers
136 views

Is it better to use the linker to compile multiple C++ files or better to include them as a header file

Assume we have two files a.cc #include <iostream> int timesTwo(int in); int main(){ std::cout << timesTwo(5) << std::endl; return 0; } b.cc int timesTwo(int in){ return in*2;...
6
votes
3answers
448 views

Why do you want to avoid flushing stdout?

I stumbled upon a question in Codereview, and in one answer the feedback was to avoid std::endl because it flushes the stream. The full quote is: I'd advise avoiding std::endl in general. Along ...
1
vote
1answer
101 views

How many bytes is a long in a 64 bit machine [closed]

I have compiled the following simple c++ code: #include <iostream> int main(){ int a = 5; int b = 6; long c = 7; int d = 8; return 0; } and here is the assembly: pushq %rbp ....
16
votes
3answers
1k views

How does GDB pause an execution

As you may know, we can use GDB and set breakpoints on our code to pause execution for debugging. My questions is, how does GDB pause a process and let you view the content of registers using i r for ...
-1
votes
1answer
137 views

What is the C++ equivalent of a logging facade in Java?

I'm currently writing a library in C++ and was wondering if I should log from within it. Googling the issue I came across this question but it makes reference to a logging facade. Is there anything ...