The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
4answers
203 views

How would I add up enumerator values such that any combination provides a unique number?

Backstory (You can skip) I am writing a pronunciation library for irregular words. Take something like the following: T1E1s // tee one E one es | tee one E ones 1994-1995// 1994 (minus|dash|to|) ...
0
votes
1answer
84 views

What OOP design pattern would work best for an overseeing class connecting related objects enforced at compile-time?

The Problem I would like to create a managing "overseer" class that connects several related object groups together where any particular group is able to be easily swapped for another using C++11 ...
2
votes
5answers
573 views

Advantages/Disadvantages of Compiling as Both C and C++?

So I've seen some C libraries written so that they compile without any changes with a C++ compiler, for example Lua. What are some advantages and disadvantages of doing this? A few basic ones I see ...
4
votes
2answers
2k views

C++ : What is the order of function pointers inside vtable?

In this answer to "In C++ why and how are virtual functions slower?", the author mentions below point: "Get the right function address from the vtable into a register (the index where the correct ...
1
vote
2answers
253 views

How can I make dll that can be called from several programing languages?

As of right now I am building authentication library for let's say programing site(It needs to be included in the program). The problem is that there several languages are used and I want to make ...
1
vote
1answer
109 views

Architecture/Design for Hardware Control Software

I'm currently working on the control software for a system that includes a lot of user controllable hardware and also has many configurations. Configurations in this context refers to a specific ...
2
votes
1answer
202 views

Suggestions for documenting namespaces with Doxygen

Consider several C++ classes which are all defined in a particular namespace. For cleanliness, each class is located within its own file, and are each well-documented. For the purposes of completing ...
-5
votes
2answers
161 views

What is the proper way to unspecify an integer's value in C++? [closed]

// Default initialization int i; // i has an unspecified value return i; // Probably 0, but Unreliable i = 5; // i has a specified value i = int();// This will give it a specified value, 0 i = ...
2
votes
1answer
126 views

C++ design pattern for template instantiation based on run time information?

Say I want to be able to create objects for a range of template parameter template<int a> class Myclass : public MyclassSuper{...}; And I want to create objects like Myclass<...
5
votes
1answer
320 views

What is the right way to create a build system?

I'm a student, and I don't have much expirience with the building process. In the last few days i've read something about CMake and others build system generators, but other than that I don't know ...
3
votes
1answer
104 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
174 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
124 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 ...
6
votes
1answer
312 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, ...
3
votes
1answer
143 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
223 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
107 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
230 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 ...
3
votes
2answers
605 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
199 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
296 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
72 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 ...
6
votes
1answer
251 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
904 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
815 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
122 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
125 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 ...
8
votes
1answer
392 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
172 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
206 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
127 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
173 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
150 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
114 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
99 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
339 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
272 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 ...
-1
votes
1answer
104 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
280 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
149 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
2k 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
135 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
438 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
91 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
234 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
570 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
435 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 ...
2
votes
3answers
267 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
72 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 ...
9
votes
4answers
1k 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 ...