Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
4
votes
3answers
154 views

True cost of virtual dispatch in C++ - when stop using it?

What I've learned so far as a programmer has lead me to think that the easiest way to write large scale software is to use a lot of interfaces - this makes things very easy to isolate and test. In ...
0
votes
1answer
83 views

How to Unit test / design differently a complicated free function

I have written a Command Line Interface, where the user has to construct an object basically by providing input to a bunch of questions. I have a hard time testing these functions as there is too much ...
-5
votes
0answers
48 views

Advice for Intermediate/Advanced C++ Developer

First and foremost I must say that I am in debt to whoever uses his time to provide helpful advice to this post. I think we have a wonderful community and it is thanks to people like you reading this. ...
2
votes
0answers
71 views

How to design software driver for the analog to digital converter?

I have been developing software driver for the analog to digital converter in C++. The a/d converter is primary intended for conversion of the temperature signals. The temperature signals are then ...
-4
votes
1answer
107 views

How do I manage multiple nested for-loops without using multiple variables?

If I have code that looks like this: int i; void functionA (){ for (i=0; i<10; i++){ functionB(); } } void functionB (){ for (i=0; i<20; i++){ doSomething(); } } ...
-5
votes
2answers
64 views

Library protection in C++

We have developed an algorithm that processes some data at runtime and is slight efficient in terms of time and computing compared with other solutions out there. Though we sure anyone can develop a ...
4
votes
2answers
249 views

Most expressive way of allocating member data, per Stroustrup

I was watching a lecture by Bjarne Stroustrup from 2014, on "The Essence of C++". About halfway through he rather forcefully recommends not using new, delete, or pointers for class member ...
-3
votes
0answers
78 views

How to decrypt a file to memory and run it from memory using c, c++, or python?

I have experience with the basics of encryption and decryption and handling files stored on the filesystem using c, c++, and python. But one curiosity I've recently encountered is how someone might ...
-3
votes
0answers
22 views

What are the pros and cons of having update sources as member references?

I have a class whose instance relies completely on updates from an instance of a separate class. Simplified example: #include "Source.h" class ObjectThatNeedsUpdates { public: ...
9
votes
5answers
2k views

C++ “Zero Overhead Principle” in practice

As an exercise in code architecture, I was writing a C++ wrapper for a window library called GLFW3. In this library, when a window's X button is pressed, you can register a callback that reacts to ...
1
vote
1answer
115 views

Templates for generic code and code flexibility

I have a data which is a std::vector of a "small collection" of items of a given type struct Bunny {};. I was vague about "small collection" because for now it's a collection of ...
1
vote
1answer
131 views

Easiest way to build and distribute Excel UDF add-in capable of Statistical Analysis

01 - BACKGROUND: I'm a typical non-programmer R user for 6+ years. Which means: i) I`m comfortable with the language most of the time and have written R packages for myself, but ii) writing C++ code (...
-2
votes
1answer
33 views

distributing application for windows with dlib

I wrote an application which uses dlib library. I use appveyor to build both (dlib and my app) for windows and it works perfectly fine (I do not have windows on my machine). The problem is that on ...
0
votes
3answers
228 views

C++ - Is it bad practice to use compiler specific functions?

My requirement is simple, I want to be able to count the number of bits in a number. With a little bit of research, I found that MSVC has __popcnt, GCC has __builtin_popcount and so on. At this stage,...
0
votes
1answer
38 views

Software driver for remote digital inputs

I have been facing a task to develop a software driver in C++ for a chip which makes available 8 digital inputs over the SPI bus. In the time being I have been thinking about the interface of the ...
1
vote
1answer
133 views

How significant is the speed of native code for back end tasks?

Going native is extremely good for front end development. Whether its using android vs ionics, c++ vs dotnet/java, the benefits to GUI are significant. I was wondering if the same had significant ...
6
votes
1answer
215 views

When to ever use source files in modern c++?

I started programming in C++ about 6 months ago and started off like many, structuring projects in a C like way. I split .cpp (source) and .hpp (header) files and used virtual classes for interfaces. ...
1
vote
0answers
67 views

How to develop software drivers for the mcu peripherals in C++?

I have been developing a set of software drivers for the peripherals of a MCU. I need to implement those drivers in the C++ programming language. My idea was to model each driver by its own class. ...
2
votes
2answers
125 views

Providing same API implemented in multiple languages

Our budding (currently internal) API deals with building information models, originates in our main application written in c++. There is a small implementation of it in C# for easy interop with other ...
-7
votes
1answer
101 views

method and class overloading (good programming practice or ridiculousness) [closed]

I have yet to hear an answer from anyone as to why overloading of any type is a sound programing practice. Calling the same function name with an almost infinite number of variations on the surface ...
2
votes
2answers
106 views

good design for signal handling in main executable

I have a executable that starts up some resources, spins a bunch of worker threads and then waits in a loop for the done command. After the done command is received, it does a bunch of clean up and ...
1
vote
1answer
143 views

Best way to structure multiple constants C++

Context I'm developing a chess engine of my own, where if anything can be pre-initialized/pre-calculated, should be. This is because speed is the number-1 priority, and every extra second you spend ...
1
vote
1answer
80 views

Is this a good use of template specialization? Or should the factory method be used?

I have a program that involves two different data structures, and so I created a class that acts as a generalized data structure that either of the original two can be represented as. (Because the ...
2
votes
4answers
254 views

Using output arguments in C++ to avoid dynamic allocations

I have a function that repeatedly encodes Foos to string. I'm currently deciding between two ways to implement this: Return by value: std::string encode(const Foo& foo); void important_function() ...
1
vote
2answers
122 views

Is there a difference between abstract data type and interface?

From what I understand, an abstract data type is basically some data and what we are allowed to do with that data (ex. a list with a set of data and an attribute size and the functions get(), set(), ...
27
votes
6answers
8k views

What does it mean when you say C++ offers more control compared to languages like Python?

I am comparing C++ with Python. It is clear that C++ is much more efficient and that the C++ code compiles directly to machine code whereas in Python it is interpreted. I do understand that Python is ...
2
votes
1answer
100 views

Ask for suggestion: data type for parsing stringified fractional numbers

I am the author of a C library for parsing INI files. So far I have delegated the task of parsing values as numbers to the standard atoi() family of functions. However I think time has come that I ...
3
votes
3answers
441 views

Why am I getting complex errors even with simple C++ code?

I started to play with C++ recently. One of the difficulties I have quite often is when the compiler tells that there is an issue with the types: more often than not, those compiler errors look ...
1
vote
3answers
96 views

What's a good way to inplement a “delete” function for my custom polymorphic widgets?

I'm currently trying to make a simple program with UI where a user can add, select and remove different objects inherited from an abstract common interface with a mouse. What I plan to do is use a set&...
-2
votes
3answers
271 views

How to avoid giant main function because of dependency injection

I try to use dependency injection as often as I can but every time I end up with the same problem : I always have a giant main function. If I use it without any framework and send the classes in the ...
1
vote
2answers
172 views

How to avoid cascading dynamic casts?

So, in general casting and dynamic_cast in particular are to be avoided. But I don't see a proper alternative for this: List<DerivedA*> ListA; List<DerivedB*> ListB; Bool Add(Base* obj) { ...
0
votes
1answer
64 views

Implementing C++ n-ary tree with Boost Graph Library

I would like to have a relatively small and simple tree in C++. Each node would contain an integer. The tree should be traversable both ways. I know it can be done with tree.hh by Kasper Peeters, but ...
1
vote
1answer
160 views

What's an efficient way to serve hundreds of gigabytes of text records to search clients in C++?

I am building a three-tier architecture application that receives compressed (zlib) text records from a data store, decompresses the records into structs, and then serves the records to clients over ...
2
votes
1answer
83 views

Are there any C++ command pattern implementations which make it easy to add additional functions and their parameters

For my situation I have a device receiving string commands such as turn_on, pump, etc. Some of these commands also have arguments attached to them such as an int. I have methods like this void turn_on(...
1
vote
2answers
113 views

C++ Organizing classes for easy unit testing (but with some restrictions)

Mild pickle. I have a project which has components that are difficult to test/mock. It might look something like this: class Contenxt; class Server : public SomeOtherClass { public: ServerPlugin(...
2
votes
2answers
152 views

Is switching sub-class at runtime a proper use case for inheritance?

I've got a DataSource base class and a few different sub-classes. I want to be able to switch which sub-class i'm using at runtime so I'm doing the following : // pointer for our datasource object ...
5
votes
1answer
199 views

Create C++14 library where each class has 2 similar variants

I'm writing a C++ library which does some computation on vectors of audio data. The library supports both GPU (using Thrust, a C++ STL-like library for GPUs) and CPUs (using the STL). I'm using CUDA ...
1
vote
3answers
179 views

Efficient way to encode moves and container choice for chess moves for an engine

I am working on my chess engine in C++ and I went for bitboards to represent the board. It is basically a 64-bit number for which I use the bitset library. I feel the most crucial part in performance ...
2
votes
1answer
157 views

How to store a vector of smart pointers, except some of them are owned by another object?

I'm making a basic platformer game. I have a Game class as well as Level class. The game object holds a pointer to the current Level object. A level currently has a std::vector of GameObject raw ...
0
votes
2answers
298 views

Why are some languages called platform dependent if I can always share the source code?

I was reading about erlang when I read that it is platform-independent, using BEAM as the VM, now I understand that a VM compiles the byte code to machine code and this makes that language machine-...
-3
votes
1answer
150 views

Data structures or coding styles in C++ for avoiding long elseif chain when parsing?

Lately I have created some small parsers of data. My initial code structure // more cases here ... else if(!strcmp(X,"somekey")){ // Parse according to "somekey" behavior. } // ...
1
vote
0answers
61 views

What is a good design for accumulating temporary data stemming from several processing runs?

I would like to compute cycle times for some manipulator movements. These movements consist of different phases. I have a class that models these phases and this is its constructor to give an idea: /**...
-2
votes
1answer
123 views

What is the point of inheritance in c++ programming? [duplicate]

Classes in c++ can be extended, creating new classes which retain characteristics of the base class. This means we can create something like this : struct Person { struct Person** children; ...
1
vote
3answers
159 views

Is it a good practice for functors to store outputs as instance attributes?

The question pretty much says all, but let's look into a simple example (I'm using C++, but the question is not strictly related to any particular language): So, let's say that we have a functor that ...
1
vote
2answers
137 views

Going from Javascript to C++. I have teacher and student objects, and I want to display if they are teachers or students. How should I do this?

This may be too general of a question, but basically whenever I try to find an answer for something that would work from a Javascript approach, the answer heavily implies that you wouldn't do it that ...
2
votes
1answer
447 views

how to represent functions and global variables in UML?

I'm going to translate into UML a C++ project I have been doing for a few days and which I estimate convenient to handle as a model for a way better management. The problem is the following: I tried ...
0
votes
1answer
94 views

How to maintain SRP with a chain of async functions?

For code maintainability I understand that it is generally better to have code structured like this: void abc() { a(); b(); c(); d(); } Instead of like: void abcd() { a(); bcd(...
0
votes
1answer
96 views

Capture by value/reference and early/late binding

Is capture by value (x below) an early binding and capture by reference (y below) a late binding in C++ lambdas, or are they both early bindings—the first by value and the second by reference? #...
5
votes
1answer
170 views

Real-world scenarios for protected inheritance

C++ supports protected inheritance: A class can derive from a base class B in a way that the "outside" world doesn't see that class "as a B" but the class itself and it's derived ...
6
votes
6answers
529 views

How is design using C different from C++?

A employer is looking for C programmers, and I'm told they say that ... Good C design isn't the same as good C++ design ... and so they're looking for candidates experienced with C and not only C++. ...

1
2 3 4 5
50