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.

3
votes
4answers
269 views

Design two classes that are closely related

I have the following basic design points: Let's say I need to design 2 entities, ADecoder and BDecoder, which are almost the same, except for few details. Let's say both have a function decode() ...
3
votes
1answer
204 views

Best practice for grouping related constants

I'm working on Finite Element code in MATLAB, and the number of constants (for instance user input defining the geometry, physics, numerical solution scheme) is substantial. Currently, I've been ...
6
votes
2answers
374 views

Abstraction of VAOs, VBOs and Models

I have gone down the rabbit hole that is abstracting away a working game engine in OpenGL and C++. Before reaching the other side I'd like to ask about my current design, which is - the more I look at ...
0
votes
1answer
96 views

Name of different patterns of acting on data in libraries.

I contribute to a couple of open source software, and I've noticed two types of patterns when classes act on data. I am interested in the name of these patterns. The first is something that goes ...
0
votes
2answers
154 views

Manage the Lifetime of GUI States

I am designing a program responsible for a GUI (with the graphics and user input being managed within a typical update loop) which has several states: The default state is an animation which ...
1
vote
3answers
191 views

Class invalid flag vs exception

So i have the following. I read in lines from a text file. Each line needs to be analysed and get the important data extracted (I wont go in the details here). I worte a Parser class which does this ...
-1
votes
2answers
139 views

Solutions for preventing build breakage

Some background to my question: We have a traditionally windows-only C++ code-base which we are in the process of porting to linux. Parts of the system have been running on linux for many years, but ...
1
vote
0answers
293 views

Inter-system communication design on Windows (C++)

I was wanting to create a program consisting of 3 elements: A central component with no UI which will work on HTTP traffic and trigger one or more “worker” elements as needed A monitor component ...
0
votes
1answer
248 views

Passing data to an unknown variable

I am developing a project that uses serial communication to interface between a micro-controller and my computer. I want to be able to pass what variable I want to change as well as the data to be ...
-1
votes
2answers
325 views

How to port gcnew and gcroot from Visual C++ to gcc [closed]

I have the task to port some code from Visual C++ to gcc. Some calls are gcnew and gcroot to handle managed code inside cpp module. How can these calls be ported to gcc in a fashionable way?
0
votes
2answers
119 views

Version checking when reading deeply nested structures

I need to open a game save file, read it, maybe modify it and then save it. The structure of the save is quite simple: it is an object with some members, some of which are data, while others are ...
102
votes
10answers
18k views

Is it ok to use meta-programming even though not all of my colleagues understand it?

I employ a lot of meta-programming to avoid repetitive tasks and build safer-to-use abstractions. I recently moved to a new job where I am working in a larger team and this worries some of my ...
-3
votes
1answer
951 views

c++ - implimenting an in memory database [closed]

I'm practicing various C++ exercises. In this particular exercise they are asking me to implement an in memory database. I guess they are not asking me to use something like SQLlite. Could anybody ...
0
votes
1answer
226 views

Relative merits of monolithic repository over multiple smaller ones

I was tasked with implementing a networking stack. The software is self-contained with no external dependencies - it only needs the C++14 standard library, and a POSIX platform. In my opinion there's ...
0
votes
1answer
99 views

What are the dangers/downside of unit tested dynamic library(DLL) being different from released library?

This is similar to: https://stackoverflow.com/questions/1278831/unit-tests-in-production-release-code# but more specific. At the moment the DLL I ship and the DLL I use for unit testing have ...
1
vote
1answer
143 views

How should end-users install dependencies for software [closed]

Suppose I have an application written in C++, which uses WxWidgets (or some other library) for gui. When an end-user installs my application, how do I make sure they also install the necessary ...
5
votes
4answers
425 views

Return an indicator if the process is succeed or not

I have member function that looks like: Point find_the_special_point(Image img); However, this function may fail to find the point (for example the img does not contain a special point at all). ...
3
votes
5answers
853 views

Fastest way to find all numbers with digits

I have a huge set of over a million numbers of variable lengths. ['773', '2267', '8957251', '170597519', '373590109', '982451707', '999999937', ......] Now given a bunch of digits, say 3 and 7, I ...
57
votes
9answers
8k views

Readability versus maintainability, special case of writing nested function calls

My coding style for nested function calls is the following: var result_h1 = H1(b1); var result_h2 = H2(b2); var result_g1 = G1(result_h1, result_h2); var result_g2 = G2(c1); var a = F(result_g1, ...
1
vote
3answers
739 views

Architecture of gui application

I am writing gui application. I want to implement following structure: project tree with nodes of different type and behavior (i.e. when right clicking or selecting there can be different menu ...
1
vote
1answer
704 views

How to control optional dependencies of a header-only library in `CMake`?

I am developing my own header-only library that I want to use as a framework in other software. I am using CMake for setting up demo targets, tests, and so on. However, I am unsure how to deal with ...
1
vote
2answers
755 views

what is an empty method and how are they used?

what is an empty method and how are they used? I was reading a documented about the BUILDER Pattern and I got a curious about how it is implemented in C++. The author defines that in C++ could be ...
0
votes
3answers
672 views

Memory segmentation - stack, heap, etc.?

So memory segmentation can be done with or without paging. I always hear people talking about stack and heaps when discussing something memory related in C++. However, what I do not get is that if the ...
0
votes
0answers
94 views

How to translate from managed to native class definitions

I have an input file, being the DLL of a C# piece of code, containing managed class definitions. I also have a *.json file, who determines how the conversion should be done. As an example, this is ...
1
vote
3answers
276 views

design pattern for class with data attached

I have a class Tiles that looks something like this: class Tiles { public: void AddTile(int x) { tiles_.push_back(x); } std::vector<int> tiles_; } Now I want to create a class Tiles with ...
3
votes
3answers
140 views

How to implement e-book reader page scrolling with variable page size?

I'm a CS student and in order to practice my coding skills I'm trying to implement an e-book reader and I want some advice from more experienced programmers. I'm using C++\QML but I'll try to keep my ...
0
votes
1answer
206 views

Beginner C++ question about program design with unique_ptr and vectors [closed]

I am currently making a console program about buying property in a city. Properties can be bought from the city by someone, transferred to another person, or returned to the city if the person who has ...
2
votes
3answers
211 views

Are Instanced APIs a Problem in a C Interface?

So an Instanced API is one that behaves like an object. So for example: foo* GetInstancedAPI(); void MemFuncSetter(foo* fooThis, const int arg); int MemFuncGetter(const foo* fooThis) const; This is ...
2
votes
3answers
1k views

How is dependency injection different from simple interface usage?

While trying to solve an issue, explained on the StackOverflow forum, somebody advised me to use dependency injection. For personal reasons, the moment a person mentions to me the usage of a design ...
2
votes
1answer
99 views

Reusing UI elements between two different QWidgets

I am writing a utility in C++ with Qt which communicates with an embedded device. The program was originally going to be used to just plot data from the device, but a new requirement has been added (...
1
vote
4answers
421 views

Unit test a generic floating point equality function

I've written a function that tests two floating point numbers for approximate equality (see this Code Review question). I'd like to unit test my function, but I'm not positive of the best way to do ...
7
votes
1answer
469 views

Handle Optional Logging in High-Performance Library

I'm writing a library in C++ which needs to be as fast as reasonably possible. However, I'd also like to be able to provide logging in case a user (or me) needs to debug possible problems. This ...
11
votes
5answers
871 views

How to design exceptions

I'm struggling with a very simple question: I'm now working on a server application, and I need to invent a hierarchy for the exceptions (some exceptions already exist, but a general framework is ...
-7
votes
1answer
322 views

Importance of storage in c++ [closed]

I want to know that whether storage is an issue with respect to current hardware and software market when we talk about the large size of C++ programs?? Because in certain conditions we have to choose ...
21
votes
4answers
3k views

Use abstract class in C# as definition

As a C++ developer I'm quite used to C++ header files, and find it beneficial to have some kind of forced "documentation" inside the code. I usually have a bad time when I have to read some C# code ...
7
votes
3answers
1k views

How to use 'Adapter' without any changes in the existing code in c++

Here we have TV class and DVD class as example: class TV { public: TV(); virtual ~TV(); void on() const; void off() const; }; class DVDPlayer { public: DVDPlayer(); ~...
3
votes
2answers
956 views

“Crossing Boundaries” in Clean Architecture

I am a layman without any programming-like education but I spent the better part of my free time to get into programming bots for some games in first AutoIt and then C++. I was introduced to ...
1
vote
0answers
50 views

How should I set up the listener service for a dynamic user interface?

So I'm working on a project and I'm running into conceptual problems in creating my user interface. It's for a DirectX11 multi-monitor game I'm writing. I've got a prototype working, with entity ...
1
vote
1answer
650 views

When writing a Qt application is good practice to ALWAYS prefer Qt function implementations, data types, and classes when they are available?

I'm just starting out with Qt and I really want to try and keep my application as separated from Qt as possible in case I decide to use a different toolset later, but at the same time don't want to ...
4
votes
2answers
191 views

Is there a valid use case for the using namespace directive?

I looked trough some of my older code and found that I was using the using namespace directive. From what I read in a lot of google results, it seems that it is never a good idea to use this. Is there ...
3
votes
3answers
363 views

Should I divide C++ program into multiple interacting applications?

We are discussing proposal to split a big C++ program into multiple separate executables that would communicated using shared memory. The shared data structures are large, so we do not want to use ...
15
votes
8answers
5k views

Should there be assertions in release builds

The default behavior of assert in C++ is to do nothing in release builds. I presume this is done for performance reasons and maybe to prevent users from seeing nasty error messages. However, I'd ...
15
votes
3answers
4k views

When should I use string_view in an interface?

I'm using an internal library that was designed to mimic a proposed C++ library, and sometime in the past few years I see its interface changed from using std::string to string_view. So I dutifully ...
1
vote
1answer
67 views

architecture of gui app with several indepedent windows and sqlite backend

Let's assume that I have such a simple database scheme: CREATE TABLE tbl(key INTEGER PRIMARY KEY, cap TEXT NOT NULL); I want to show at least three independent GUI windows. One window (window A) ...
2
votes
0answers
92 views

Access modifiers in combination of interpreter pattern with template method pattern

Motivation: (Skip to "The Problem" if you don't need motivation for it) As a project for myself, I'm writing an expression parser for certain kinds of mathematical expressions, and I'm using the ...
1
vote
1answer
335 views

How to organize the management of resources for OpenGL?

I write my own 3D-graphics engine for education and have some difficulties with it's architecture. I wrote classes like OpenGLTexure, OpenGLMaterial, OpenGLGpuProgram, etc. I also wrote a class ...
9
votes
2answers
4k views

Proper design to avoid the use of dynamic_cast?

After doing some researches I can not seem to find a simple example resolving a problem I encounter often. Let's say I want to create a little application where I can create Squares, Circles, and ...
3
votes
1answer
165 views

How do you add feature to a class that was originally designed wrong in the first place? [duplicate]

I have a Surgeon class that is constantly changing class Surgeon { string name, discipline; public: Surgeon(string _name, string _discp) : name{_name}, discipline{_discp}{} void writeDir(...
59
votes
3answers
9k views

What's the reason for not using C++17's [[nodiscard]] almost everywhere in new code?

C++17 introduces the [[nodiscard]] attribute, which allows programmers to mark functions in a way that the compiler produces a warning if the returned object is discarded by a caller; the same ...
1
vote
1answer
115 views

Inheritance or strategy in my circular buffer

I've looked at some other threads but they don't quite answer my question, I think... I have a CircularBuffer object which I have separated from a ThreadSafeCircularBuffer object so that the CB logic ...