We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
-2
votes
0answers
62 views

Need help in Classes, Maps,Lists from C to C++ Application [on hold]

I am from C background, trying to write a C++ application. Below is the code i have come up, the purpose of application is to store a list of countries,and to create a mapper between the name of the ...
4
votes
3answers
183 views

How to adhere to the Open Closed principle in a procedural language like C

In Robert Martin's seminal 1996 article "The Open-Closed Principle" he presents an example in C which does not follow the principle (the DrawAllShapes() method is not closed for modification): enum ...
-4
votes
0answers
23 views

Libedit usage for command history implementation [on hold]

I am trying to implement command history into an existing project. I am about to make use of 'libedit' commandline editing functionality. Any help or suggestion to get started. Should I write new ...
2
votes
2answers
86 views

Processing user commands and parameters

I'm writing a GUI application which needs the facility for users to interact with the system and execute tasks via a sort of command line interface. The user will type commands in a text box, with ...
1
vote
1answer
222 views

What are the possibilities to embed GIT into application in order to manage version control of the projects that were created by that application?

I am developing an C++ application, which creates tree like structures (collections) of strings. I want to add the ability to save the information of these tree structures remotely/locally (can be ...
25
votes
7answers
6k views

Can abstractions and good code practice in embedded C++ eliminate the need for the debugger?

I am a C developer for an embedded system. YouTube has recently started recommending "C++ for embedded systems" talks. Having watched some of them, they pique my interest, but none of them answer the ...
10
votes
5answers
688 views

why aren't the platform specific integer types in C and C++ (short, int, long) deprecated?

TL;DR: Why isn't everybody screaming, "Don't use short, int, and long unless you really need to, and you very likely don't need to!" I understand that, in theory, by using the types short, int, and ...
4
votes
1answer
73 views

Coupling and shared entity classes

I am currently working on a problem that has a central controller that is handling inputs and outputs between various modules and maintaining a number of entity classes as these change. When working ...
-3
votes
1answer
64 views

How to make code runnable on open source code editors like Ace Editor?

For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor. However, I feel ...
3
votes
1answer
101 views

Keep track of intializations done in a function

There is an initialization function in my app that does multiple inits. What is a good way to keep a track of inits done so that if init n fails all inits done before it must be cleaned up/de-init ...
-2
votes
0answers
31 views

Quickest route from point A to Z through all other points

I'm a novice in graph theory and I'm looking for a relatively easy algorithm [implementation] for finding the most efficient route from point V1 to point Vk through all points V2, V3, ... , Vk-1. The ...
1
vote
1answer
84 views

Public class members in PIMPL

I'm attempting to use the PIMPL idiom. This is my public header file in include/foo.h: class FooPrivate; class Foo { public: Foo(); ~Foo(); private: FooPrivate* p_impl; }; ...
1
vote
2answers
129 views

Is there a natural architecture design where I should use mutable member variable(c++)?

I have come across mutable variables kind often, yet it seems to me it's always been use to solve a problem of design(typically coping with legacy code) rather than to answer a natural, intrinsic ...
0
votes
0answers
53 views

C++ client-server design

The context I need to design a Client-Server(-Client) network in C++ that would allow an android application to communicate to a Raspberry Pi and back I am running everything on linux environment(s) ...
2
votes
2answers
202 views

How to best unify different data formats?

I have a hardware device connected to the computer and on the hardware device there is 512 bytes of memory for storing parameters. I want to read this data and decode the parameters stored in the ...
3
votes
4answers
365 views

How to use Macros in Programming to make code faster, efficient and compact

Recently I was going through some of the solutions of the best competitive programmers in the world. I found out that those people use a template while writing the programs, preferably in C++. I ...
3
votes
5answers
497 views

Is there a way to speed up a big switch statement?

As a practice I'm working on a CPU simulator (runs at about 1.78MHz) and I'm using a switch statement to execute correct opcodes based on the value in the IR (instruction register) variable. This ...
-2
votes
1answer
50 views

OOP classes hierachies for aiding static checking justified?

upfront I develop software for big data applications of which use is beyond my control (it ends up with a user), but I am not a trained software developer. So I apologize for any wrong terminology. ...
3
votes
1answer
81 views

(C++) Ideal design pattern for associating requests/responses on socket?

I'm working on my first big C++ project and while I understand the language I'm trying to learn elegant design patterns using it. I have some low-level networking over a UDP sockets API where each ...
2
votes
2answers
255 views

Why doesn't C++ support covariance in STL containers like C# or Java?

The Covariance and Contravariance feature is well supported in C# and Java collections. However C++ doesn't support them in their STL containers. Why is it so? For example the below code will ...
39
votes
3answers
14k views

Why is the logical NOT operator in C-style languages “!” and not “~~”?

For binary operators we have both bitwise and logical operators: & bitwise AND | bitwise OR && logical AND || logical OR NOT (a unary operator) behaves differently though. There is ~ ...
3
votes
2answers
172 views

How can I cleanly handle deeply nested namespaces in C++?

The first language that I truly learned was Java. In it, it is very syntactically easy to nest classes in an essentially arbitrarily complex package hierarchy, which keeps the code organized. It is ...
50
votes
11answers
10k views

Why does C++ have 'undefined behaviour' (UB) and other languages like C# or Java don't?

This Stack Overflow post lists a fairly comprehensive list of situations where the C/C++ language specification declares as to be 'undefined behaviour'. However, I want to understand why other modern ...
1
vote
1answer
74 views

Simple question about terminal memory [closed]

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
115 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 ...
3
votes
3answers
396 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
73 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
215 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
154 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 ...
2
votes
1answer
299 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
vote
2answers
222 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 ...
2
votes
0answers
45 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
80 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
157 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 ...
1
vote
2answers
109 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
154 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
215 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
246 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++). ...
1
vote
2answers
486 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. ...
2
votes
0answers
91 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
106 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
452 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
103 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
85 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
211 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
38 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
70 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
189 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 ...