Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
5
votes
1answer
219 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 ...
4
votes
3answers
356 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},...
2
votes
1answer
287 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 ...
-1
votes
2answers
156 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 ...
2
votes
0answers
83 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 ...
1
vote
2answers
108 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 ...
2
votes
1answer
109 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 ...
30
votes
5answers
8k 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 ...
1
vote
1answer
81 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 ...
1
vote
2answers
161 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 ...
0
votes
1answer
80 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 ...
2
votes
1answer
237 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?
2
votes
2answers
226 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 ...
0
votes
0answers
78 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). ...
0
votes
4answers
197 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 ...
1
vote
1answer
116 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::...
0
votes
0answers
43 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 ...
0
votes
0answers
44 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. ...
2
votes
2answers
77 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 ...
3
votes
0answers
93 views

Windows c++ (piracy): strategies for preventing multiple binaries from being cracked by a single patcher [duplicate]

I am developing a piece of commercial software for Windows, that requires users to obtain a license key in order to use it. It is run locally by clients with the assumption that their machine may not ...
0
votes
1answer
28 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 ...
4
votes
5answers
754 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 || ...
4
votes
4answers
353 views

Do we really need interface classes for the dependency inversion principle?

As a practical example, imagine a Gripper class which represents a robotic gripper in a simulation. Gripper has a TryGrip method, which checks if there's a GrippableItem in the correct position (...
-1
votes
1answer
151 views

In C++ and GCC on Linux, is it possible to allocate memory to your swap space instead of your RAM?

I have a large hash, around 6 gigabytes that I load into memory. On my current laptop that I develop from, it really does a number on my system, causing massive amounts of lag while I try to go about ...
2
votes
5answers
246 views

Splitting class responsibilities without exposing private data

I'm struggling to find good ways to split up classes without exposing private data. Most articles I read about SRP seem to ignore how the new classes that take on the separated responsibilities access ...
1
vote
2answers
214 views

How to declare and share a lot of variables to provide best performance

My question is not about dilemma between clean code vs performance, but I want to understand exact issue with declaring variables and sharing them between functions. I read in many threads, that from ...
1
vote
0answers
52 views

External standalone cpp code in my project

I've inherited a project that has a codebase in src/, but it also has precompiled binaries of dependency software in bin/. I would like to move away from having precompiled software as part of our ...
5
votes
2answers
212 views

Where can I put project dependencies

I've just finished my studies in Computer Science and now I'm working. The problem is I'm the only computer scientist in my company and I'm probably taking a lot of bad habits. I would like to correct ...
0
votes
2answers
401 views

Logically, is there a reason why ++i++ can not be a valid expression?

I had to increment my integer twice in a loop, so I thought I would try and be clever: for (int i = 0; !sl.isEmpty(); ++i++) { ... } ++i++ however is not an assignable expression, at least in GCC. ...
3
votes
2answers
233 views

Am I using namespaces wrong?

I'm obsessed with organization - it's probably the real reason why I enjoy coding. So I namespace everything. But I'm just curious if I'm doing it wrong by being redundant. Consider this, which I ...
6
votes
1answer
199 views

Is it practical to pass function pointers to a separate class to avoid additional includes?

In my program I've included the header for an external library (GLFW) in my Main class. Everything I need to use that library for can be handled in my main class, with the exception of two sneaky ...
6
votes
4answers
288 views

How to explicitly inform users of the class that calling a method will invalidate the object it was called upon?

Consider this snippet: class Foo { int m_fileDescriptor; public: Bar transformIntoBar() { Bar bar(m_fileDescriptor); m_fileDescriptor = -1; return bar; } }; ...
1
vote
2answers
88 views

const function parameters and default behavior

Say I have a C++ function /** * @param path If empty, the system default is used */ void foo(const std::string& path); And in my implementation I have a default handling for empty paths void ...
7
votes
7answers
580 views

Relevance of optimization techniques

I've heard of some techniques to optimize code and make it faster: On one side are clearly relevant optimization: use of better algorithms, benchmarking, etc. On the other side are techniques with a ...
0
votes
0answers
59 views

Different approaches to plugin system

Having an application that defines a plugin API, I was wondering how (if possible at all) to achieve both stability and performance (see below for what that means) at the same time. A plugin in my ...
1
vote
2answers
331 views

Simple Snake Game in C++

I posted this question originally in Code Review, but then thought that I could possibly get more feedback about the design here. I just finished writing a simple Snake clone in C++ with the goal of ...
0
votes
0answers
32 views

Best practice for installing kernel files alongside OpenCL programs?

OpenCL kernels are compiled at runtime, so have to be installed together with the program (if you are using seperate .cl files, like me). Are there best practices regarding where to install kernel ...
0
votes
4answers
125 views

Design pattern for embedding constructor arguments into classes/structs

I am still quite new on here so I hope I am posting in right forum. I am currently writing a small library where I realized I could use some kind of design pattern which lets one pass constructor ...
24
votes
4answers
5k views

Why is the norm of a complex number in the C++ complex library actually the square of the norm?

In the C++ complex library, the method norm() of a complex number actually returns the square of what I have learned is usually called the "Norm". Reference: std::norm For example, std::norm() of (3,...
1
vote
1answer
89 views

How to simplify work with class inheritance when a lot of arguments needed to be passed to c-tor?

Let's say I have class that used inside another class and uses inside some nested fields of it. To simplify the example I'll use trivial types. In reality it's something like DataType dataType, Status ...
2
votes
0answers
98 views

c++ exceptions, should the caller add the context or provide it to the callee?

Here is a piece of code. Basically, I load some source files, all of them are compiled separately, and then I link all of them. LinkedObject loadObject(std::vector<std::string>& fileNames) {...
-1
votes
2answers
119 views

Developing a C++ program on linux using two threads, always keeping one thread running

The title describes an idea of a solution to a more general problem. Here is the general problem: I am developing a program which looks roughly as follows: [read a lot of data, store in data ...
-2
votes
1answer
98 views

Design a generic hardware interface

I am trying design a generic hardware facade interface for different camera types. below is my incomplete generic interface for camera devices template <class Data,class Configuration> class ...
-1
votes
2answers
99 views

where to put Read/Write threads in c++ classes

I am programming a UART interface (in LINUX) and I want to use a class for that. The way I have it right now is I have a method for write and one for read. The reading is started in a new thread to ...
5
votes
2answers
473 views

Is it good approach to await async tasks in object destructor?

I'm currently working on class with some async tasks under the hood. In fact I need to delegate few tasks to asynchronous execution and be sure that all of them are finished before class was destroyed,...
1
vote
0answers
44 views

Include a database .h file in the factory or in the class in C++

I have a factory, GuiTable.cpp where I create multiple GUI-related classes. I also have a database class, CommonStrDatabase.h which serves as a database file for different strings used in the GUI. ...
0
votes
0answers
87 views

Best design for referring to compile-time set of values at runtime

I am designing an internal API that deals with images. As part of this, I hit this use case where: I specify an image format as a single value. An image format implies a collection of settings (...
4
votes
3answers
494 views

What's the purpose of multiplying by 1024x1024?

I'm working with an old C module that was originally ran on Power PC architecture and compiled with gnu 3.0.6 I'm porting it to run in a VS2012 project on Intel hardware. The module creates a 3D ...
2
votes
1answer
125 views

Optimal design for improved performance of a simulation code

I'm writing a code for the Discrete Element Method where I have balls (spheres) and walls (planes) interacting with each other. Those simulations are run for billions of time steps, so performance ...
1
vote
1answer
167 views

Whats a proper way to design a GUI event system?

I'm trying to write a GUI library for a project (also for learning purposes) from scratch (in C++), and it's working pretty well, but since this is my first attempt i feel that the design of the event ...

1
2
3 4 5
50