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.

5
votes
5answers
214 views

Designing for 3rd Party Extensibility

I'm having trouble understanding how to provide an API to 3rd parties in order to allow extensions for desktop applications. I understand that if I'm using a compiled language (e.g. C++), I can load ...
4
votes
4answers
263 views

C++ Preferred method of dealing with implementation for large templates

Typically when declaring a C++ class, it is best practice to put only the declaration in the header file and put the implementation in a source file. However, it seems that this design model does not ...
0
votes
1answer
67 views

Abstract data communication in modular design

I'm doing the analysis for a software which I've had in mind for a long time. Its purpose is to turn sound into an image, apply graphical transformations on it, and turn it back into sound to hear the ...
25
votes
2answers
3k views

Implementation of pure abstract classes and interfaces

Although this isn't mandatory in the C++ standard, it seems the way GCC for example, implements parent classes, including pure abstract ones, is by including a pointer to the v-table for that abstract ...
0
votes
1answer
119 views

Can source code, automake and configure files for multiple OS co-exist in one Git branch

I am working on an open source project that should be compiled for multiple operating systems including Ubuntu and Windows. I am working on how to structure the Git repositories and branches for ...
1
vote
0answers
29 views

Applying an overloaded/templated function depending on the type of a QVariant

I'm trying to take a QVariant (in this case from a QProperty generated on a class) and based on the type, return a QWidget that allows for it to be edited appropriately. a signature for the ...
-3
votes
1answer
101 views

Enforce that all dervied classes and subclasses always define a member function

How to do I enforce that all classes that have class A as base define EveryClassHasThis()? Class A { public: virtual void EveryClassHasThis() = 0; } For example in the below simple case; how to ...
1
vote
2answers
201 views

Using C coding conventions in C++ code [duplicate]

I'm working on a large codebase whose core modules are in C and extension modules are in C++. We have a coding convention for C code but I'm being told that we need to enforce the same coding ...
-1
votes
1answer
341 views

Combining the arguments of a function using a single structure

What are the consequences (pros and cons) of using a single structure as the argument, instead of a list of parameters. Some of the advantages I see are: create multiple default parameters. Need not ...
3
votes
2answers
1k views

How to deal with exceptions in DLLs?

I recently started working on an existing project written in C++ Builder. The application consists of a MainModule that loads lots of modules (DLLs). The MainModule itself is a DLL (there is a small ...
2
votes
0answers
76 views

Creating bindable input handler in C++ spanning two separate modules

I have a wxWidgets application. This is the first, main module. The second module is an openGL engine. It's a model-view-(controller) structure, where application is the view (and the controller), ...
4
votes
2answers
575 views

How is usually named a non-const getter?

Quite often you need to define a getter returning a reference to a member, and a corresponding setter. They usually look somewhat like this : class Foo { Type member; public: const Type& ...
2
votes
1answer
195 views

Designing a pause'able & resume'able task handler

I don't think the title describes the situation exactly. I apologize for the poor description. I'm trying to write a software system, in C++, that will have a heavy job (scanning the file system for ...
2
votes
2answers
404 views

Is this Aggregation or Composition?

As far as my understanding for composition, the children cannot exist without the parent. But my instructor is suggesting that the following example is an aggregation, I just want another opinion. ...
0
votes
2answers
262 views

Code Coverage and Defensive Programming (in private functions)

Assuming you want to build automated tests for the following (very simple, if odd) class. // Calculates the distance between neighboring values in a vector // and provides functions to return the ...
1
vote
5answers
644 views

Designing a card game

I want to expand my personal projects portfolio, so I decided to make a card game. To be more precise, it's called Macau. I've read this answer on StackOverflow and tried to follow the steps from the ...
4
votes
2answers
602 views

Implementing reference counting from scratch or using shared_ptr for resource?

In an OpenGL application that I am writing, I want to have a simple shader class to wrap the OpenGL shader handle. Ultimately, I want this shader class to behave very similarly to a shared_ptr in c++ (...
2
votes
3answers
1k views

Proper way to send custom data structures by sockets

I'm wondering what is the proper way to send structures as char array by sockets. At this moment I have somethig like below but it isn't good solution because it causes undefined behavoiur. Is it ...
5
votes
4answers
756 views

Is this using macros to define classes that fit a pattern in C++ a sound idea?

I've got a set of classes that all inherit from a base class that are responsible for different functions (sort of like a group of "operators") They all work on the same input and output the same ...
2
votes
4answers
849 views

Is “Let more people able to review” a valid reason to “write c++ as if Java” at some degree?

According to Should we avoid language features that C++ has but Java doesn't?, I know it is horrible to write C++ as if Java, mostly because it drops the beneficial features of C++ languages. But ...
13
votes
5answers
8k views

Is passing arguments as const references premature optimization?

"Premature optimization is the root of all evil" I think this we can all agree upon. And I try very hard to avoid doing that. But recently I have been wondering about the practice of passing ...
0
votes
1answer
878 views

Using a macro for a libraries namespace?

In some code bases (such as hydra, and thrust's tuple implementation) I see namespaces defined entirely with macros. It appears the reason for this is so that you can configure the namespace to your ...
1
vote
1answer
220 views

Is it wrong to prefer exceptions to centralize error handling logic?

Using C++, often I hear that you should avoid throwing exceptions for flow control and you should avoid calling functions in conditions where you know they will throw. For example, if a function ...
-2
votes
3answers
169 views

Platform independant ways of passing messages between executibles

I am working on an a data collector which could be called an API of some sorts, which is based on .Net Core 2.1 . It's job is to receive and pull (ask for) data from data collectors(executable, DLL,...
2
votes
3answers
836 views

High level overview of how printf() works with Windows OS

I asked this question on an IRC channel, sadly I am going around in circles. I am aiming for a high level overview (but with some technical details if necessary) on how a function such as printf() ...
2
votes
2answers
197 views

Designing a Way for Process to Communicate with Kernel

I've got a project that is sort of a virtual operating system. In this project, the Kernel class is responsible for creating Process classes. The process class consists of Thread classes and the ...
1
vote
1answer
174 views

Limitations of using classes as interface

I am an Electrical Engineer now training and working as an embedded software developer, so I have little formal computer science and software design training. I have until a few months ago only worked ...
0
votes
1answer
306 views

Advantage or disadvantage of using = operator or uniform initializer while using auto keyword

Most examples of auto use the = operator. #include <iostream> int main() { auto a = 1; std::cout << a << '\n'; } Why don't they use the uniform initializer like this? #...
24
votes
7answers
11k views

Should the STL be avoided in large applications?

This might sound as a weird question, but in my department we are having trouble with following situation: We are working here on a server application, which is growing larger and larger, even at the ...
3
votes
1answer
477 views

How to deal with large source codes?

Maybe this answer already exists here, but I do not know if there is any technical term for that. I'm starting to develop in C ++ and as the program grows in size, it gets harder to move through the ...
7
votes
3answers
529 views

Where should I put my enum classes?

I have some code that looks like this: // Player.hpp class Player { public: enum class State { RUN, WALK, STAND }; }; The enum class State is used by the Player class, as well as by many other ...
3
votes
3answers
200 views

How to separate serialization, visualization and computation from GUI editable code objects?

This might be an X Y problem, but here's my situation. I've got a QT5 C++ code base whose task it is to allow for the configuration of a "process chain". A "process chain" here means a list of ...
-1
votes
1answer
382 views

Does it make sense to iterate a ranged for loop using constant reference here?

I have the following code, and I was wondering if I'm optimally iterating through my ranged for loop: struct data_type { int a; int b; }; int main() { // Assume I have initialized a ...
-4
votes
1answer
394 views

TIOBE Index: why c++ is in 3rd place and C is having more land in the last year?

Searching for c++ ranking on the TIOBE index, I was stumped to see that C is in front of C++, and from 2017, C took a leap. Could someone explain why?
7
votes
7answers
3k views

Best practice to “continue” from inside a nested loop?

Here is a simplified sample. Basically, it does checks on a string from a string list. If the check passes, it will remove that string (filterStringOut(i);), and it is no longer ...
2
votes
2answers
255 views

(Style) “Good” way of dealing with flags/options

So I've seen many different methods used for this in different librarys, and I want to get a sense of which one may be preferred (or perhaps it's strictly personal preference/case by case). Just as an ...
1
vote
2answers
200 views

Large matrix manipulation in multithreaded environment

I have: matrix 20*40000 of floats M - std::vector<std::vector<float>>; 1000 values X; ~2000000 POD structures S. A typical situation is: for each value from X I take several structs from ...
1
vote
1answer
1k views

Difference between header files and interfaces

I wanted to know whether the header files in c and c++ have same function as that of interfaces used in Java? If not what is the difference between header file and interface?
2
votes
0answers
2k views

How to improve a pattern 'enum class with methods'

Over many years, I always find myself reconsidering this design, so I wanted to get some feedback on my solution to it. Problem: I need a limited amount of objects = instances from a class, and I ...
5
votes
3answers
2k views

Moving from Qt/C++ to C#/WPF - Productivity Gain?

I created a small Desktop application (approx 15000 lines of code, so not that large) written in C++/Qt. This is non-commerical, just a hobby project and I am coding on my free time. The larger the ...
-2
votes
2answers
129 views

How to call more than one program from a single process in an efficient way?

i want to call more than one process from the main program which is written in C++. how to call them with the most efficient way given that one process may open and close more than one time. the ...
1
vote
2answers
191 views

Picking a concrete type based on a configuration parameter

I have a code base that contains several different instances of the following pattern, the key point of which is that the concrete type of the class is decided at run time based on a string from a ...
1
vote
2answers
205 views

Does increase of number of classes have impact for performance

I'm in the middle of refactoring a project (in C++11) and I'm struggling with a decision is it good to change huge enum with about 100 record to separate classes. This enum is used in about 4 places ...
6
votes
3answers
2k views

What is the correct approach to test classes with inheritance?

Assuming I have the following (over-simplified) class structure: class Base { public: Base(int valueForFoo) : foo(valueForFoo) { }; virtual ~Base() = 0; int doThings() { return foo; }; ...
7
votes
2answers
390 views

FIFO Min-Max-Heap for Rolling Median

I'm working on a system with hard real-time constraints in c++ and I need a very fast way to calculate the rolling/moving/streaming median of a set of numbers of size N=100 to 300. Normally this size ...
0
votes
2answers
515 views

What is the safest practice in handling QWidget pointer lifespan in a QObject oriented environment?

Consider the following constructor: NetworkTools::NetworkTools(QObject *parent) : QObject(parent) { view = new QWebEngineView(); view->setParent(parent); // Produces an error, shown below. ...
-1
votes
1answer
173 views

Multi module project version management

I have a CMake multi module project made of a library and an executable. Both the root project and each sub module has its own version (major.minor.patch). I would like to know how to handle each ...
2
votes
2answers
167 views

Object set-up for testing: Manipulate the object or use its functions?

Assuming I have the following (very simple) class class Foo { public: void setAB(int a, int b) { m_a = a; m_b = b; m_aIsBigger = a > b; } int getA() const { return m_a; } int getB() ...
0
votes
3answers
3k views

C++ design - vector classes with different element types

I am trying to design a group of related classes. For example: one table class holds a vector of integer, and has a function returning integers from the vector another table class holds a vector of ...
0
votes
0answers
125 views

A program, written in native code, needs to access data, read by a managed DLL

I'm working on an application, which needs to base itself on a DLL, written in managed code (C#), in order to function. That DLL contains type definitions. Therefore a convertor has been written, ...