Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
2
votes
2answers
51 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
87 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
18 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
659 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
296 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
96 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
4answers
148 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
193 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
49 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
200 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
370 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
220 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
189 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
268 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
86 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
556 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
56 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
165 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
31 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
122 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 ...
23
votes
4answers
4k 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
84 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
92 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
114 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
95 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
96 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 ...
4
votes
0answers
192 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
42 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
86 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 (...
2
votes
2answers
394 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
120 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
147 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 ...
4
votes
3answers
255 views

How to adhere to the Open Closed principle in a procedural language like C

In Robert Martin's seminal 1996 article "The Open-Closed Principle" he presents an example in C which does not follow the principle (the DrawAllShapes() method is not closed for modification): enum ...
2
votes
2answers
92 views

Processing user commands and parameters

I'm writing a GUI application which needs the facility for users to interact with the system and execute tasks via a sort of command line interface. The user will type commands in a text box, with ...
1
vote
1answer
242 views

What are the possibilities to embed GIT into application in order to manage version control of the projects that were created by that application?

I am developing an C++ application, which creates tree like structures (collections) of strings. I want to add the ability to save the information of these tree structures remotely/locally (can be ...
25
votes
7answers
6k views

Can abstractions and good code practice in embedded C++ eliminate the need for the debugger?

I am a C developer for an embedded system. YouTube has recently started recommending "C++ for embedded systems" talks. Having watched some of them, they pique my interest, but none of them answer the ...
10
votes
5answers
870 views

why aren't the platform specific integer types in C and C++ (short, int, long) deprecated?

TL;DR: Why isn't everybody screaming, "Don't use short, int, and long unless you really need to, and you very likely don't need to!" I understand that, in theory, by using the types short, int, and ...
4
votes
1answer
87 views

Coupling and shared entity classes

I am currently working on a problem that has a central controller that is handling inputs and outputs between various modules and maintaining a number of entity classes as these change. When working ...
-3
votes
1answer
143 views

How to make code runnable on open source code editors like Ace Editor?

For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor. However, I feel ...
3
votes
1answer
109 views

Keep track of intializations done in a function

There is an initialization function in my app that does multiple inits. What is a good way to keep a track of inits done so that if init n fails all inits done before it must be cleaned up/de-init ...
1
vote
1answer
93 views

Public class members in PIMPL

I'm attempting to use the PIMPL idiom. This is my public header file in include/foo.h: class FooPrivate; class Foo { public: Foo(); ~Foo(); private: FooPrivate* p_impl; }; ...
1
vote
2answers
134 views

Is there a natural architecture design where I should use mutable member variable(c++)?

I have come across mutable variables kind often, yet it seems to me it's always been use to solve a problem of design(typically coping with legacy code) rather than to answer a natural, intrinsic ...
0
votes
0answers
65 views

C++ client-server design

The context I need to design a Client-Server(-Client) network in C++ that would allow an android application to communicate to a Raspberry Pi and back I am running everything on linux environment(s) ...
5
votes
2answers
243 views

How to best unify different data formats?

I have a hardware device connected to the computer and on the hardware device there is 512 bytes of memory for storing parameters. I want to read this data and decode the parameters stored in the ...
3
votes
4answers
484 views

How to use Macros in Programming to make code faster, efficient and compact

Recently I was going through some of the solutions of the best competitive programmers in the world. I found out that those people use a template while writing the programs, preferably in C++. I ...
3
votes
5answers
523 views

Is there a way to speed up a big switch statement?

As a practice I'm working on a CPU simulator (runs at about 1.78MHz) and I'm using a switch statement to execute correct opcodes based on the value in the IR (instruction register) variable. This ...
-1
votes
2answers
64 views

OOP classes hierachies for aiding static checking justified?

upfront I develop software for big data applications of which use is beyond my control (it ends up with a user), but I am not a trained software developer. So I apologize for any wrong terminology. ...
3
votes
1answer
88 views

(C++) Ideal design pattern for associating requests/responses on socket?

I'm working on my first big C++ project and while I understand the language I'm trying to learn elegant design patterns using it. I have some low-level networking over a UDP sockets API where each ...
2
votes
4answers
423 views

Why doesn't C++ support covariance in STL containers like C# or Java?

The Covariance and Contravariance feature is well supported in C# and Java collections. However C++ doesn't support them in their STL containers. Why is it so? For example the below code will ...
42
votes
3answers
14k views

Why is the logical NOT operator in C-style languages “!” and not “~~”?

For binary operators we have both bitwise and logical operators: & bitwise AND | bitwise OR && logical AND || logical OR NOT (a unary operator) behaves differently though. There is ~ ...

1 2 3 4 5 48