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
1answer
65 views

What is the right way to create a build system?

I'm a student, and I don't have much expirience with the building process. In the last few days i've read something about CMake and others build system generators, but other than that I don't know ...
-1
votes
0answers
26 views

FTT audio processing for an audio spectrum audio spectrum [on hold]

Background: I want to make a fast and responsive audio visualizer (in real time). I want to use the GPU for the Fast Fourier Transform because almost everyone that has Steam installed has an APU/GPU ...
0
votes
1answer
24 views

How do I create a ribbon desktop application in C++ in Visual Studio? [on hold]

I want to use Visual Studio and want to create a C++ Desktop Application with the Ribbon UI, but everywhere I look, I can't find a solution that would help me get started or I must have missed ...
2
votes
1answer
57 views

Design Review Of SOLID Principles For An Autonomous Mobile Robot

I am self-learning robotics, C++ and good object oriented design. I have asked various questions over the past couple of weeks: 1 and 2 that have lead to the following design. The design goal is for ...
4
votes
2answers
2k views

Constructor vs casting operator

I'm programming a library (so I have complete access to all the mentioned classes). Two classes (A and B) are essentially the same and differ only by their implementation, so they can easily be ...
2
votes
1answer
139 views

Would de-coupling using interfaces/templates make the system easier to maintain at the cost of over-engineering?

I have been practicing this hybrid approach for dependency injection in the last couple of days and I am wondering if it should also apply to components which are within the same package? For example:...
2
votes
1answer
622 views

How would you design a “multithreaded” LRU cache using C++ (unordered_map and Linkedlist)?

Please note that this is about a thread-safe LRU cache (not simply a LRU cache as specified in https://leetcode.com/problems/lru-cache/description/). It isn't a duplicate of LRU cache design question ...
0
votes
1answer
123 views

C++11 freeRTOS questions about queue usage and object design

Background I'm writing C++ firmware with freertos to penplottingrobot. It's a makeblock XYplotter and the firmware is connecting to mDraw software for command instructions thru USB drivers. MDraw ...
18
votes
7answers
38k views

Why do we need to include the .h while everything works when including only the .cpp file?

Why do we need to include both the .h and .cpp files while we can make it work solely by including the .cpp file? For example: creating a file.h containing declarations, then creating a file.cpp ...
2
votes
1answer
154 views

Approach for implementing Device and Protocol layers in C++?

I'm writing a program that will interface with an external device. It will support numerous devices that may use different communication interfaces like USB, serial, etc. This is what I have so far: ...
1
vote
2answers
3k views

Why use SDL and OpenGL instead of just OpenGL?

I've been seeing people combine SDL2 and OpenGL (glfw.h or glut.h) for a while now, I've done some research and found out SDL2 runs on OpenGL. So why does people combine these two? Some people ...
-2
votes
7answers
2k views

C++ namespace name isolation

It's been considered for a reason, that using for namespaces/names is side-effect-prone, and generally, fully qualified names should be preferred. I've come up with an approach on that, which I ...
29
votes
10answers
15k views

Do we still have a case against the goto statement? [duplicate]

Possible Duplicate: Is it ever worthwhile using goto? In a recent article, Andrew Koenig writes: When asked why goto statements are harmful, most programmers will say something like "because ...
0
votes
1answer
110 views

How can I vary the distance function in my code?

I have a simple design question. I have a tree based C++ class. It needs to use a distance function in order to calculate nearest neighbors. But the distance function is available from an external ...
5
votes
1answer
241 views

Is it better to use lambda functions or boolean variables to record state

I have heard some people claiming that boolean state variables are generally bad and should be avoided when possible. Apparently in many cases it is possible to put state into lambda functions, ...
11
votes
3answers
5k views

non-optional pointers vs. non-const references in C++

In Other C++ Features, Reference Arguments of the Google C++ Style Guide, I read that non-const references must not be used. All parameters passed by reference must be labeled const. It is clear ...
2
votes
2answers
210 views

What is the difference between a static library and an archive library?

In the comments of a recent answer, I equated a static library with an archive of compiled object files. The response was that they are not the same, so what is the difference? To clarify - gcc ...
2
votes
1answer
63 views

different collision geometries in a component based game engine

I'm writing a simple game engine and after a lot of rethinking/refactoring I settled with sort of a component based architecture (not strictly ECS, but it isn't inheritance based anymore either). So ...
44
votes
1answer
4k views

Which C# practices should be avoided in C++? [closed]

I'm currently teaching myself C++. I'm very proficient at C#, and was wondering which common practices in C# can lead to difficulties in C++, and what a C++ programmer should do instead.
1
vote
4answers
191 views

Should I always use iterators when working with strings?

Here is the known old way to iterate over the string: for (int i = 0; i < str.length(); i++) { char c = str[i]; } However recently I have also seen in multiple places the usage of ...
7
votes
9answers
3k views

Is it any good to use binary arithmetic in a C++ code like “C style”?

I like the fact that the C language lets you use binary arithmetic in an explicit way in your code, sometimes the use of the binary arithmetic can also give you a little edge in terms of performance; ...
2
votes
1answer
91 views

Design approach for extending class functionality - Embedded C++

For my company i am refactoring our embedded C/C++ code base to increase re-usability for commonly used functionality. Currently i am refactoring our command line interface but i ran into a design ...
15
votes
4answers
546 views

Should I add the source of libraries instead of linking to them?

I'm relatively new to C++, so I'm not sure how I should best handle small dependencies (e.g., a scripting language, or a JSON/YAML/XML Parser). Should I create separate projects and link them as ...
4
votes
2answers
1k views

GO - Goroutine and Concurrency

Background: pthreads follow pre-emptive scheduling, whereas C++ fibers follow cooperative scheduling. With Pthreads: the current execution path may be interrupted or preempted at any time This ...
0
votes
1answer
94 views

Network programming (boost::asio), architecture and communication protocols

I'm trying to make a simple network application using boost::asio. I think that I understood the basic things like io_context, async functions etc, but I really don't know how to deal with buffers. ...
2
votes
2answers
151 views

Should smart pointers be exposed in a C++ API?

Exactly as the name says, should smart pointers be exposed in a C++ library API? I've used quite a few C++ libraries and haven't ran into exposed smart pointers yet. Given that it's very common to ...
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
1answer
114 views

How to obtain and store a subgraph of a graph in C++?

I have implemented a graph structure (for graphs having ~30,000 nodes and ~300,000 edges) as follows: class graph; class node; class edge; class graph { public: graph(){}; vector<node*> ...
1
vote
1answer
67 views

Library with different runtime behaviour based on usage history (design question) [closed]

I want to design a hash table library that keeps usage statistics and based on how it is used will use different implementations at runtime. For example use a certain implementation for small size ...
5
votes
1answer
178 views

What is the best way to handle glue between different classicly OOP objects at the higher levels of abstraction?

In object oriented programming, it is commonly said that each class/object/instance should have a well-defined purpose. For example, there may be a Window class in a windowing toolkit, a ChunkLoader ...
4
votes
3answers
275 views

How to reach the parent object?

I have a parent object that has some other objects as fields. The parent object fully owns these fields: they can be declared as fields of the parent object (MyPart part), directly, not as references. ...
11
votes
2answers
13k views

Are Nested Static Library dependencies possible?

I am working in QT . Can a static library depend on another static library?(Static Lib is made by linking another static lib) If yes, is it possible that after linking to lib2, the generated lib(...
5
votes
4answers
391 views

Writing mockable code in C++

I am focusing on writing easy to test code these days and I realize that most of my classes follow the skeleton below: Some class ObjectManager needs a DatabaseRepo, while there is only one type ...
5
votes
1answer
226 views

Is there any reason *not* to forward declare all forward declarable function parameter/return types?

I ran into a situation where my build speeds have started to become large and have affected productivity. I had already minimized header dependencies before using forward declarations. Now I've ...
4
votes
3answers
6k views

Where should I place a typedef when used in method signatures in C++?

I'm using an Optional class quite similar to that of boost. For semantic reasons, I switched an attribute of the same (structured) type in some class definitions (and therefore also in method ...
2
votes
1answer
112 views

How to write a class that uses other classes but needs the same functionality - should I just wrap around the methods?

I want to create a class ProcessHandler for Windows that pretty much uses the WINAPI. The class ProcessHandler should be able to scan memory, emulate keyboard and mouse, needs some DLLInjector, some ...
1
vote
1answer
109 views

What is the best way to handle the scenario in C++ where there are two methods that are identical, except one is const?

I am currently working on a program in which I encountered an issue (not for the first time) where I have two acessor methods for a data structure. The methods are identical, except one is const and ...
23
votes
7answers
12k views

If a variable has getter and setter, should it be public?

I have a class with a variable that is private and the class has a getter and a setter for that variable. Why not make that variable public? The only case I think you have to use getters and setters ...
7
votes
0answers
222 views

Securely sandboxing user scripts in a C++ program

I've been working on a personal project in C# whose purpose is more or less to allow the user to execute scripts written by other users and restrict the permissions of that script. My program compiles ...
15
votes
4answers
3k views

C++ 'using': Should I use it or should I avoid it?

I realize there are subtly different semantics for some of these, because of ADL. In general, though: Which one should I prefer (if any), and why? (Or does it depend on the situation (e.g. inline ...
5
votes
2answers
157 views

Help with dependency inversion

I'm learning about Binary Trees in school and I'm trying to apply the SOLID principles to it. My problem is in my BinaryTree::insert() method I'm creating a new BinaryNode, and from what I've ...
5
votes
1answer
114 views

Working with “external” object IDs

I have often encountered a situation in which users of a program (not necessarily human, just an external agent) need to be able to reference objects of a class with a certain "external" identifier, ...
-1
votes
1answer
84 views

Wait and wake-up vs. start and join for multithreading

A function that is repeatedly called should do multiple tasks: request a vector from a server. calculate a new vector. send this latter to a server. append the new vector summed to the downloaded one ...
-2
votes
2answers
127 views

How to handle multiple versions of binary file format

I'm writing a reader for the custom binary file format used in one game. The format has multiple versions for example: struct FileHeader { ushort version; uint fieldX; // version 1 uint ...
36
votes
4answers
76k views

What is LPCTSTR?

what is LPCTSTR and LPCTSTR-like (for instance HDC) and what it does stand for?
1
vote
1answer
101 views

Chain accessors or return the value of private pointer

I am having trouble thinking through what best-practice dictate I do in this situation. Say I have the following class structure Class A { public: bool isCompressed() { return compressed_; } ...
0
votes
1answer
94 views

Streamlining development process of Linux C++ CLI app [closed]

On Linux Mint 19 with C++ compiler version: g++-8 (...) 8.2.0 I am compiling and running my project named: getPixelColor Using a shell script: #!/bin/sh g++-8 -std=c++17 -Wall -Wextra -Werror -...
0
votes
1answer
108 views

Class holding collection of other class

I have a class Item. Then another class ItemCollection holds std::map<int,Item> item_collection_. The reason to create the class ItemCollection is if I want to do something with collection of ...
29
votes
6answers
23k views

Programming language usage at Google [closed]

I have heard Google uses Python, Java and C++. But what I don't know is how is each of those programming language is used. I mean what is Python, Java and C++ is used for at Google. Why would they ...
1
vote
3answers
225 views

What is late binding?

I know, there are lots of sources on the internet, but I do not understand them. Wikipedia: "Late binding, dynamic binding, or dynamic linkage is a computer programming mechanism in which the method ...