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
2 answers
375 views

Is it good practice to throw exceptions in parsing functions

I basically read across the entire internet that exceptions are bad, slow and should be avoided whenever possible. This confuses me because I thought I have a "valid" case to use exceptions. Consider ...
user avatar
2 votes
4 answers
485 views

Wrapping 3rd party library - avoiding leaking abstraction

I'm currently developing an application using SFML. My biggest concern at the moment is making a layer of abstraction over the library, so I can easily change it to something else if needed. What I'm ...
user avatar
  • 203
-1 votes
2 answers
78 views

commonly used practices for deploying package primarily composed of bash scripts

I am working on a tool that primarily uses bash scripts and C++ code. Generally I have experience with basic tools written in C and C++ in which we can have a build system like ./configure; make; ...
user avatar
3 votes
3 answers
207 views

Should you define an equality test solely for testing?

Assume you have a class C. C defines a public method (member function) C::m1. Calling c.m1() (c is an instance of C) can either Return after mutating the object c it was called on. Throw an ...
user avatar
-4 votes
1 answer
78 views

Using only the Cache not the DRAM in a Program (USB to Ethernet) [closed]

I am reading some data from USB, do some packet processing and then send the result to the Ethernet port. The USB ports are connected to an onboard USB Hub where it communicates with the ...
user avatar
  • 93
1 vote
1 answer
171 views

Is there a standard technique to implement command line options within programme for CLI?

I am writing a command line tool in C++ that takes several arguments, some of them file names but also option parameters. Is there a standard way to parse and implement these options? A simple way ...
user avatar
  • 129
-2 votes
1 answer
87 views

Are jagged arrays lvalue or not?

When I was study lvalue i see that C expression can be lvalue if a subscript ([]) expression that does not evaluate to an array. (from https://docs.microsoft.com/en-us/cpp/c-language/l-value-and-...
user avatar
0 votes
0 answers
170 views

How can you multithread an html parser [ in C++ and similar languages ]?

Ive done two HTML parsers. Done with Regular Expressions [that accounted for nesting]. It was quick, but error prone. Done by evaluating Character by Character through switches. Here was the basic ...
user avatar
  • 3,319
0 votes
1 answer
86 views

How to define values dependant on the derived type?

My base class must provide an interface to get a value that is dependent solely on the type of the derived class. I can think of two ways of implementing this: Solution A, virtual functions: class ...
user avatar
  • 111
0 votes
2 answers
695 views

In C++, Why do bitwise operators convert 8 or 16 bit integers to 32 bit?

Is there a logical reason why the integer is upgraded to 32+ bits? I was trying to make an 8bit mask, and found myself a bit disappointed that the upgrade will corrupt my equations. sizeof( quint8(0)...
user avatar
  • 3,319
-2 votes
1 answer
68 views

In C++, does it make sens to have library project be composed of other libraries?

I'm working on a C++ project which is currently divided into "sub modules" / "components". Each of these are compiled into a separate library (components are usually 10-20 files). The libraries are ...
user avatar
1 vote
1 answer
74 views

Writing a data-oriented ECS update loop that handles multiple components

So I have an engine in progress that's structured like this: entities are simple ids (unsigned short) components are stored in pools which are static members systems are stored by the manager, and ...
user avatar
-2 votes
1 answer
190 views

Designing a sqlite component in C++

I work on a small component in an embedded device (sensor). This component : Every 5 seconds, sends requests to other components using sockets (get health check status, operating status etc) and ...
user avatar
  • 137
0 votes
1 answer
122 views

How to avoid messy code when working with different libraries

I'm planning to work with different libraries that use different conventions. One uses snake_case, another one uses camelCase. This leads to code that looks like I can't make up my mind: Some_Result ...
user avatar
62 votes
10 answers
16k views

I never use pointers in my C++ code. Am I coding C++ wrong? [closed]

This question may sound strange to you, but I am learning C++ all by myself. I have nobody whom I could ask for mentoring and I would be very glad for some advice. I have started recently to program ...
user avatar
0 votes
1 answer
162 views

What's the added value in the sophisticated use of C++ templates advocated by Alexandrescu and others?

In general terms, what's the added value in using the techniques described in the iconic book "Modern C++ Design"? Is it simply the ability to write reusable code that's easily extensible? Or are ...
user avatar
-3 votes
1 answer
93 views

Best way to pass an optional parameter to a program

In a couple of my programs, the program needs to know an IP address and a port to which it should connect or send data to. The solution I have right is to ask for user input via the console - but ...
user avatar
2 votes
2 answers
165 views

How can I improve this design to achieve a more loosely coupled system and better testability?

My question I built an inverted pendulum on an Arduino using C (ie. everything was done procedurally). I'm trying to self study application design and would like to refactor my code into a more OO ...
user avatar
  • 157
-1 votes
1 answer
251 views

Do other languages have variables shared between threads?

I guess it would be too complex for Node.js / JavaScript to leverage, but I've been working with clusters in node to break big tasks down so all cores can work at once but the inter-process messaging ...
user avatar
  • 3,833
0 votes
1 answer
1k views

fake filesystem for unit tests

I am writing an application in c++ and Qt5. It would be very convenient for me to create a virtual file system so I can unit test code working on files. I have found that in Qt4 there was a ...
user avatar
6 votes
1 answer
699 views

Procedure for migrating a large C++ code base to use smart pointers

I am in the process of refactoring a large C++ code (~2300 files, ~600K lines, mostly older C/C++98 style code) and there are definitely memory leaks that could be shored up using C++ smart pointers. ...
user avatar
  • 171
2 votes
2 answers
284 views

C++: Achieving a decoupled "Definition is Registration" paradigm for derived classes?

I'm trying to engineer this: 200 subclasses [ Derived Classes ] After a subclass is defined, I wont need to edit any other file. [ Decoupled ] Subclass Definition registers itself. [ Definition is ...
user avatar
  • 3,319
2 votes
1 answer
141 views

Publisher-Subscriber architecture with central registry

Problem description Publisher-Subscriber architecture with a central registry where agents can either promote their capabilities or search for a given capability. The project must be developed with ...
user avatar
  • 129
-2 votes
3 answers
1k views

Accessing one class variable from another class in C++

Suppose I'm in some function of class A, in this function I define an object of class B, say b, and call some function using b.func() which updates some values and arrays, say x and A. Then, I create ...
user avatar
  • 1
1 vote
3 answers
232 views

What is the best object-oriented design approach for a tree with two node types?

I have a tree-like structure as shown in below picture (as one small example). The tree consists of two different node types, that are: Data Nodes: These nodes that are colored in yellow contain ...
user avatar
  • 179
0 votes
1 answer
88 views

Handling background tasks that may not be relevant when they are completed

Imagine the following pattern: you have a window with information that needs to be updated asynchronously. You launch and detach a thread to handle fetching the information, but while the information ...
user avatar
-4 votes
2 answers
145 views

Why is C++ not updated as frequently as Java? [closed]

Java was last revised in 2020, while C++ had it's update back in 2017
user avatar
  • 125
0 votes
1 answer
145 views

To structure big and expandable project(s)

TLDR with bold I want to create a library (I think this is the right term) for my own reinforcement learning environments (envs for short). Most of the envs would be based on self-implemented games ...
user avatar
  • 37
0 votes
2 answers
608 views

Should I use a class with only static members to encapsulate my program?

So I'm writing a network simulator in C++ as part of a university project. Right now, I have a class structure that looks something like: //includes type aliases #include "GlobalTypes.h" //main body ...
user avatar
4 votes
1 answer
576 views

The case against path expressions in #include directives

I am preparing for a discussion with my fellow programmers which will be about their use of the C/C++ #include directive. The codebase which I have to retrofit to Automotive standards is using ...
user avatar
4 votes
3 answers
376 views

How to know where to draw the line between "safe" code and "over-engineered" code?

Suppose I have a class Texture that will be passed to a Renderer to be displayed on screen. One possible design is as follows: class Texture { public: Texture(unsigned w, unsigned h) : w_ {w},...
user avatar
  • 159
2 votes
1 answer
293 views

How can malware run on a pc when installed?

I had a quick question. I was working on understanding malware and then I started to wonder how was malware able to run on its own when installed? So for example, I was to click on a bad link that ...
user avatar
0 votes
2 answers
2k views

Will compiled python code be as fast as compiled C++ code?

I know that Python is an interpreted language and that c++ is a compiled one, or at least I like to think that I've understood some of their differences. Although C++ is apparently faster than ...
user avatar
2 votes
0 answers
167 views

How to separate a serialization code from application in a large c++ project

I'm working on a fairly large c++ project which uses boost's serialization. The issue that I have with the way it is currently organized is that serialization is weaved into the main source code on ...
user avatar
  • 129
1 vote
2 answers
236 views

How to create objects and allocate data only once in C++ to improve speed with octave .oct files?

I have been coding some octave .oct files lately (C++), and for my purposes speed is of the essence. It seems to me that creating C++ objects (in general) can take some time. I was wondering if ...
user avatar
1 vote
1 answer
123 views

Is it common to include a specific build of a library/ tool for production level project?

I am working with C++ in a Linux/ Unix environment. I am trying to learn the physical design of large scale projects. In one of my projects, I am using an SDK from a camera manufacturer. They released ...
user avatar
  • 123
36 votes
5 answers
16k views

Is there a way to use a C++ API in C#?

I want to code a little program that takes in head tracking data and moves a 3D object accordingly on the screen. To achieve this I found a software called opentrack that has a C++ API. The problem is ...
user avatar
  • 489
1 vote
1 answer
104 views

How to make a system of mutually related classes?

I am making a C++ glfw wrapper for myself to use. I want to have classes like Monitor, Window, Context that would be wrappers for glfw objects like GLFWMonitor* or GLFWWindow*. The problem is that if ...
user avatar
  • 123
1 vote
2 answers
168 views

Avoid class chains that emerge from DI

I am developing a hobby project where I try to use DI to get testable code. Until now, I found that it improved both the readability, usability, and testability of the code. However, now I have a ...
user avatar
  • 1,632
0 votes
1 answer
195 views

C++ Project Structure in UNIX/Linux environment: test and app folder

I am trying to figure out the right project structure for C++ and I am working on Ubuntu using CMake. I mostly work on AI/ Robotics/ Data Science. Assume that I want to generate executables and ...
user avatar
  • 123
2 votes
1 answer
265 views

Why did C++11 add find_if() instead of overloading find()?

Why did c++11 add a separate find_if() instead of simply overloading the existing find()? Wouldn't overloading the function be sufficient?
user avatar
3 votes
3 answers
590 views

Are namespace constructs like 'using std::string' unacceptable also in .cpp files?

I understand the rationale of avoiding using namespace std - this defines too many casual names the developer may not be even aware of. I tried to work around the problem with the help of using ...
user avatar
  • 689
0 votes
0 answers
109 views

How to create factories for same object type but different ways of creation following Domain Driven Design rules? (C++)

Brief description of a problem - providing factories which are creating same object type in different ways and following rules of DDD (isolated domain model, independent domain objects inside of it). ...
user avatar
  • 1
0 votes
4 answers
331 views

Open closed principle: code duplication and encapsulation

In another question on this site, asking to clarify the open closed principle, @Kate Gregory answered this. I'm interested in this part specifically: Imagine you wrote an Invoice class that works ...
user avatar
1 vote
1 answer
138 views

In C++, how would one unit test a method that must throw an exception when a private array no longer has "space"?

I am implementing an ECS system with a data-oriented design, and with a TDD methodology using Catch 2. I have the following class declaration snippet for an EntityManager: using Entity = std::...
user avatar
0 votes
0 answers
45 views

Logically equivalent conditionals, same test, but different condition coverage (google test)

Title pretty much says it. I ran into trouble getting condition coverage of a logical statement and found that the order in which the statement is written (rather than order of operations) results in ...
user avatar
0 votes
0 answers
110 views

Ensure that library has been initialized

I am using a 3rd party library that must be initialized with Lib::init() before any of its other functions may be called and that must be uninitialized with Lib::destroy() before the application ends. ...
user avatar
  • 1,632
2 votes
2 answers
143 views

Organization of C++ source code for reusable components

I'm implementing a custom templated container as part of a learning project in C++. The container makes use of different components like serialization, memory management, iterators. I am wondering ...
user avatar
  • 31
-1 votes
1 answer
50 views

Non regression test for small set of data data driven from database, how to handle future data

While writing this question I found out that I'm faced with 2 problems: a testing one and a production one but I hope that resolving the situation can solve both issues. Now the question: I have a ...
user avatar
  • 769
4 votes
5 answers
797 views

How to deal with a lot of conditions in If statement in an elegant manner

Is there a more syntactically beautiful/simply better way to write the following (without major abstraction)?: if (usart_error.CRCError == true || usart_error.DMATransferError == true || ...
user avatar
  • 81

1
3 4
5
6 7
53