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
1answer
49 views

Simple question about terminal memory

I'm running a program in C++ on a Chromebook Penguin terminal. The program runs perfectly the first time, but on consecutive runs it acquires different results. I suspect that this is because the ...
-4
votes
1answer
91 views

Is it really good idea to disable warning of C or Cpp? [duplicate]

When we are working on a big project of C or CPP, we are getting some warning. Therefore, we try to remove that warning because when we see compiler warnings that they make us feel dirty. When we ...
-1
votes
1answer
41 views

Interface between C++ and CUDA C++ [closed]

Suppose that I've implemented some CUDA C++ class, e.g., for multiple precision arithmetic (MPF, for short). All MPF's methods can be run on both CPU and GPU. Suppose that I have some library (Lib, ...
3
votes
3answers
240 views

C++ Recursive Descent Parser: Global Variable Dilemma

I'll come straight to the point. I'm trying to create a Recursive Descent Parser in C++ for a hobby project which involves creating my own minimalist programming language. One thing that puzzles me, ...
0
votes
1answer
69 views

Common methodology for organizing C++ source/header/library/resources? [duplicate]

I'm currently working on a C++ project in Visual Studio and can't make up my mind on how I should be organizing my files. As of currently, my file directory looks similar to the following. ->...
1
vote
1answer
207 views

What is the proper way to deal with rounding error?

I am currently working on a Physics Engine in C++. The Physics Engine is for a sandbox video game. I want to build a powerful physics engine, so therefore, it needs to be very precise. I have ...
2
votes
1answer
145 views

Testable class/interface in embedded software written in C++

I would like to collect feedback on possible solutions for creating testable classes/interfaces. In a normal C++ development we can use references/pointers and forward declarations to achieve dynamic ...
1
vote
1answer
232 views

Failure to understand logic behind dice roll permutation problem

I am having a lot of trouble understanding the logic behind the infamous "Find total ways to achieve given sum with n throws of dice having k faces" question. After extensively searching for ...
-1
votes
0answers
34 views

Design desicion for embedded Qt software with browser support [on hold]

I have to create a dashboard software using Qt on an embedded device (with embedded linux and a touch screen) to show some process data and to make diagnostics. Furthermore, the GUI should also be ...
0
votes
0answers
59 views

How to manage multiple build configurations with cmake [migrated]

I am trying to think through how to design a new project build system. I want to use CMake to compile for Windows and Linux. I want to have Release and Debug builds, which are pretty straight forward. ...
1
vote
2answers
204 views

Introduce code standard into old code

Our main product is written in C++ MFC and follows the same code standard as MFC. Now we will start to develop new components, and think about whether we should continue to use the same outdated ...
1
vote
0answers
35 views

Managing application versions using Conan and RPM

I have a shared object that I developed. This shared object is packaged in two forms, a Conan package, and an RPM. It is a Qt project, so it has a .pro file associated with it. Up until now, we ...
0
votes
2answers
72 views

C++ - BitVector logic

I have implemented a simple bit vector class. However, I have some problems with understanding, how to push data to it. In a standard vector, push_back inserts new element et the end. A similar ...
45
votes
9answers
9k views

How do we avoid CI-driven development…?

I'm working on a very large research-led open-source project, with a bunch of other regular contributors. Because the project is now quite big, a consortium (composed of two full-time employees and ...
2
votes
1answer
150 views

C++ How to build a common interface with the possibility to call functions specific to only one class

I am building a common interface for several different backends that are shared libs loaded at runtime dependend on the used platform. It looks basically like the code below. My problem is, that while ...
0
votes
2answers
103 views

Is inline still necessary when using the Named Parameter Idiom?

The Named Parameter Idiom as described here mentions that there will be a performance impact when not using inline. Since each member function in the chain returns a reference, there is no ...
4
votes
1answer
150 views

How to “state of the art” integrate multiple sub-modules with duplicate dependencies?

I am currently working on a project which will consist of multiple sub-modules. Each sub-module is developed and unit-tested in its own repository. All sub-modules have to be integrated in one main-...
0
votes
2answers
195 views

C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?

A couple of months ago I wrote a C++ program for computational mathematics that was supposed to compete with a highly optimized C code. After a while I did manage to get it fast enough to beat the C ...
1
vote
2answers
237 views

Memory Allocation in C++

Does the memory allocated by class pointers get freed by the class destructor once the class method/function goes out of scope? Or do I need to manually free the memory allocated by the pointer (C++). ...
0
votes
2answers
322 views

Can Rust replace the C or C++ programs in the Future? [closed]

I recently read an interesting Article that, due to a memory Overflow error Power system of Boeing will collapse and turns the Flight into a Flying Brick. This is a low level memory Handling bug. ...
1
vote
0answers
84 views

C++ dependency management across projects

We are developing a benchmarking framework in C++, with Make and CMake as build tools. The aim of the framework is to allow others who build algorithms to perform head-to-head comparison against prior ...
0
votes
1answer
102 views

Unique physical objects (Hardware drivers) in C++

I'm writing a hardware driver for the raspberry pi 2 with C++. The driver uses the SPI bus to talk to a radio chip. I made a class Radio and put all those functions that talks to the chip into that ...
0
votes
6answers
432 views

Should setters only set values?

I always like to overthink things, so here's my thought of the day: Should setters only set the values of class properties, and not perform any other logic? Suppose I have a class class User { ...
2
votes
1answer
100 views

C++ pattern for compile-time configurable class functionality

Due to resource limitations (embedded), I want to make some functionality that a class provides optional. The decision to include this optional functionality should be made at compile time. For ...
-4
votes
1answer
82 views

Exiting Recursive Function C++ [closed]

In the following function IsDoubleString(),if res is true then it shouldn't call IsDoubleString(), I debugged the code but I am unable to understand that once it hit the line returns res; why does the ...
1
vote
2answers
210 views

Minimizing code duplication without using macros or sacrificing speed

Here's a snippet of code: An inlined function: inline void rayStep(const glm::vec3 &ray, float &rayLength, const glm::vec3 &distanceFactor, glm::ivec3 &currentVoxelCoordinates, const ...
0
votes
0answers
35 views

Which components of an HTML Element, can I assume will be static over the course of its lifetime?

This is a question for people who are familiar with how HTML typically is built and behaves on webpages. Backstory and requirements I am building an HTML tracker with a C++/Qt backend. I am trying ...
0
votes
0answers
59 views

Using virtual inheritance for an interface system based on abstract classes

I want to use a physics engine (like bullet or PhysX) in my program, however I want to hide the actual physics engine from it, so I can easily swap it out with another during run-time (e.g. switch ...
1
vote
3answers
69 views

Handling errors in looper/event loop interface

I have a C++ class that spawns a thread that contains an event loop of sorts and the class provides an API to query the list of events that have occurred since the last call, i.e something like std::...
0
votes
4answers
182 views

Can int16_t be easier on the processor then int?

I know that the compiler and architecture of a processor also have a role to play in this. But this is more of a "can it" rather then a "does it" question. I have already tried to research this, but ...
8
votes
1answer
396 views

How can I optimize a program's performance when no profiling tools are available?

I am currently working on an OpenGl program whose performance I would like to improve. The performance is okay but not ideal on powerful dedicated GPUs, but is abysmal on integrated graphics (< 10 ...
2
votes
1answer
105 views

When developing for C++ in Visual Studio, is there a quick way of being able to test your code as an exe and DLL?

I'm developing some C++ code that eventually will be compiled as a DLL to be accessed with Python through CTypes. My workflow is generally that of compiling the DLL and running the Python script ...
0
votes
2answers
286 views

Dependency Injection in C++ use pointer or object?

While I am learning C++ based on how develop in modern PHP frameworks I decided to use the Dependency Injection pattern with services as Singletons. For making myself clear let suppose we have the ...
0
votes
0answers
104 views

multithreading - waiting on a condition without using locks (c++11)

i've been wondering about it for a while now but never found any answers. is it possible to use something like a condition variable without a lock? I have a vector of objects, and a thread pool, and ...
5
votes
3answers
301 views

How should a derived class be tested?

I have a question regarding proper design of tests. Suppose that there is a class A class A{ public: virtual int methodA(); virtual int methodB(); virtual int methodC(); ...
4
votes
4answers
1k views

How to check whether existing code base can deadlock

I'm improving/expanding a somewhat large code base, and I've introduced multithreading into it. But with the possibility of introducing code that could deadlock, which is nigh impossible to test for ...
-3
votes
3answers
266 views

Is it an ok practice to keep pointers dereferenced?

For me, I prefer having all my variables, not as pointers. Is it ok to keep all heap-allocated variables dereferenced? For example: #include "Foo.hpp" #include "Bar.hpp" class Foo { private: Bar* ...
0
votes
1answer
220 views

Handling Different Parameters for Derived Classes

I'm designing an API and I ended up having a few pure abstract classes. Because of the nature of the problem that I'm solving, each derived class has to be initialized with different sets of ...
1
vote
3answers
169 views

Best way to conditionally exclude unused code (C++03)

I'm working on a bare-metal embedded system, with a class that can be compiled for different hardware versions. The class takes in a pointer to a device and uses it, or takes in NULL if the device is ...
0
votes
2answers
512 views

How to prevent 'global variables' in a big project?

With 'global variables', I mean Variables on namespace level Static data members in classes Static variables in functions In a big C++ project I would like to have a mechanism (like a compiler ...
9
votes
9answers
703 views

Inheritance vs Composition For Chess Pieces

A quick search of this stackexchange shows that in general composition is generally considered more flexible than inheritance but as always it depends on the project etc and there are times when ...
1
vote
4answers
201 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
532 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
244 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
104 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
165 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 ...
-4
votes
2answers
159 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
125 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<...