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
1answer
100 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 -...
1
vote
3answers
373 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 ...
1
vote
2answers
295 views

Splitting a critical application into multiple executables

We're developing some C++ application that analyses strings using some data. The data is large (a few gigabytes) and takes a significant amount of time to load into memory, and timing, as well as ...
-1
votes
1answer
105 views

What's the best design pattern approach for introducing optional feature to current code base?

I had a class hierarchy with several classes that interact with each other. After introducing new feature that is optional (but it depends on external libraries) I have the following code (just ...
1
vote
0answers
301 views

Designing a multithreaded TCP/UDP server for audio sharing

As briefly introduced in the question title, I am trying to design and implement a server application able to let clients share audio contents between themselves. In order to achieve that, I decided ...
-3
votes
1answer
149 views

Which is the best pattern or solution for this problem?

Given the following class: class S { ... private: void Action1(); void Action2(); . . . void ActionN(); } The Action functions are related, which are called in ...
1
vote
1answer
2k views

Unit testing abstract classes with Google mock (gmock/gtest) (C++)

I want to test an abstract class with: Pure virtual methods that should be overridden in sub-classes Non-pure virtual methods that use the pure virtual methods (as opposed to this question) class Fu ...
-2
votes
1answer
137 views

Using static member methods to check for object being NULL

Is it a good practice to use the static member methods to check if an object of a class is NULL or not. The object would be sent through the parameters offcourse. Something like, #include <...
5
votes
1answer
447 views

How common are destructors in modern c++ code?

In the standard c++ library, all containers and all input/output streams have their own constructors and destructors, that handle all the relevant resource acquisition and release. So for most tasks ...
0
votes
0answers
91 views

Base class with bool flag to imitate virtual constructor

I am using bool flag to call base class function when needed to imitate virtual constructor. I am using this way for inheritance purpose. I have a Base class constructor with int and bool. The bool ...
6
votes
1answer
236 views

How can I reduce the amount of storage needed for a gravitational n-body simulation?

I am currently attempting to create a gravitational n-body simulation using a modified Barnes-Hut algorithm, to be more amicable to GPU computation. This is primarily as a learning project. My goal is ...
1
vote
0answers
651 views

Unit testing C++ in XCode

I'm working on a plugin for some drafting software. The plugin takes the form of a dynamically loaded mach-o bundle. The software vendor provides a template plugin in the form of an XCode project. ...
1
vote
1answer
664 views

One process using std::thread, 2 physical CPUs, 4 cores each, parallelism level?

Suppose I have a one C++ process, and I want this process to run eight threads in parallel. And suppose that: I have a computer with two (2) physical CPUs. Each CPU has four (4) cores, so that's 4x2 ...
2
votes
3answers
274 views

In c++, is there a way inside a function block, to execute cleanup code after the value has been returned?

Backstory (You can skip) I am building an API for managing Files and Directories in a consistent manner across a project. This is for deduplication and consistency when performing a task, and in this ...
0
votes
1answer
75 views

Avoid numerous dynamic_cast_ptr in the API design of polymorphic types

I am trying to design a geometric intersection API. Below is the code to represent geometric elements. #include <iostream> #include <memory> // Since I did not write the Shape class I ...
9
votes
4answers
2k views

C++ Iterator, Why is there no Iterator base class all iterators inherit from

I am learning for an exam and I have a question which I am struggling to give and answer for. Why does no iterator base class exist all other iterators inherit from? My guess my teacher is ...
0
votes
1answer
299 views

Difference between a strongly typed language and a weakly typed language with type annotations from the developer's point of view?

I understand that there are major technical differences between how a strongly typed language is compiled and how a type annotated language is compiled/transpiled. But as a developer writing in a ...
1
vote
2answers
107 views

Pattern for composing streaming operations without threads?

I'm working on a library that lets me write operation on an input "stream" of data (I don't call them that, but it's a potentially unbounded input regardless, think data coming from a socket). I ...
1
vote
3answers
470 views

Why is the whole Hadoop ecosystem written in Java?

Developing Big Data processing pipelines and storage, you probably come across software which is more or less a part of the Hadoop ecosystem. Be it Hadoop itself, Spark/Flink, HBase, Kafka, Accumulo, ...
0
votes
4answers
248 views

Is it better to use the linker to compile multiple C++ files or better to include them as a header file

Assume we have two files a.cc #include <iostream> int timesTwo(int in); int main(){ std::cout << timesTwo(5) << std::endl; return 0; } b.cc int timesTwo(int in){ return in*2;...
5
votes
3answers
676 views

Why do you want to avoid flushing stdout?

I stumbled upon a question in Codereview, and in one answer the feedback was to avoid std::endl because it flushes the stream. The full quote is: I'd advise avoiding std::endl in general. Along ...
1
vote
1answer
114 views

How many bytes is a long in a 64 bit machine [closed]

I have compiled the following simple c++ code: #include <iostream> int main(){ int a = 5; int b = 6; long c = 7; int d = 8; return 0; } and here is the assembly: pushq %rbp ....
16
votes
3answers
2k views

How does GDB pause an execution

As you may know, we can use GDB and set breakpoints on our code to pause execution for debugging. My questions is, how does GDB pause a process and let you view the content of registers using i r for ...
-1
votes
1answer
207 views

What is the C++ equivalent of a logging facade in Java?

I'm currently writing a library in C++ and was wondering if I should log from within it. Googling the issue I came across this question but it makes reference to a logging facade. Is there anything ...
2
votes
1answer
543 views

How to optimize reusing a large std::unordered_map as a temporary in a frequently called function?

Simplified question with a working example: I want to reuse a std::unordered_map (let's call it umap) multiple times, similar to the following dummy code (which does not do anything meaningful). How ...
0
votes
0answers
101 views

Linear “steps” of operations considered a state machine?

I have a set of tasks I perform to complete some larger operation. These tasks must be executed in linear order, and you cannot proceed onto the next task until the previous completes. For the most ...
1
vote
2answers
363 views

Analyzing stack and heap using GDB and C++

I have a simple c++ code as the following: #include <iostream> int main() { int a = 5; int *b = (int *) malloc(40); return 0; } Setting a breakpoint using GDB on line 5 and ...
0
votes
2answers
548 views

Usage of the word “override” in C++ and it's virtual functions

I know that the following function is a virtual function and needs to be overridden when extended by another class: virtual int getAge()=0; What i don't understand is the following syntax I have ...
21
votes
6answers
11k views

Why is C/C++ main argv declared as “char* argv[]” rather than just “char* argv”?

Why is argv declared as "a pointer to pointer to the first index of the array", rather than just being "a pointer to the first index of array" (char* argv)? Why is the notion of "pointer to pointer" ...
1
vote
0answers
106 views

Save data from multiple Qt components scattered around multiple QML files

I would like to save the current "value" property of several components (e.g. a Slider) as a configuration profile when the user clicks on the Save button in my application. However, the Save button ...
1
vote
2answers
261 views

Notify Millions of subscribers at the same time(or with min. delay) in C++?

I'm working on a problem, in which i have some real time weather information of different cities through out the world. I'm exposing subscribe function to interested people/clients, with input:- ...
2
votes
3answers
124 views

filesystem::path vs. optional<filesystem::path> as argument to function

Sometime ago in a code-review (C++) I suggested to change the input argument from Path type to Optional<Path>, where the function has specific logic for unset path. It looks for me intuitively ...
0
votes
2answers
145 views

Force field initialize not by constructor in c++

My parent class has a vector field I want to force child classes to push in that vector as many as items they have. At least one item example: class Options { protected: vector<...
-2
votes
1answer
76 views

How to identify test cases?

I wrote a small INI file parser as a library which I want to use in a bigger project. Following good practice I decided I should write test cases, too. But I fail to find a good start. The library is ...
3
votes
2answers
2k views

Is it good practice to statically link libstdc++ and/or libgcc when creating distributable binaries for Linux?

Context: I have an open source project which uses JNI. While it's possible to build it yourself, I expect most users will use standard Java tools like Maven, Gradle, or SBT to download the JAR, which ...
2
votes
2answers
89 views

Convert template type to derived type when calling a function?

Apologies if the title is incorrect, I couldn't think of better wording. I have the following code template <class E> void ResolveEntityHit(E& entity, Projectile& projectile) { ...
1
vote
1answer
95 views

Architecture of iterating over polymorphic types

I have a base type of Entity, and multiple implementations, Enemy, Bunker, Projectile I have separated these entities into their own containers so I can pass them to different classes to perform ...
-3
votes
1answer
164 views

Is my algorithm for determining whether a ipv4 is public or private correct? [closed]

I have just created a function which checks whether a ipv4 is public or not. I have not heavily tested it yet since it is kind of practically impossible to do so (because I do not know where to start)....
4
votes
2answers
284 views

Game Playing AI - Strategy to overcome the transposition table taking up too much memory?

I've made an engine that plays Connect Four using the standard search algorithms (minimax, alpha-beta pruning, iterative deepening, etc). I've implemented a transposition table so that the engine can ...
-3
votes
2answers
209 views

Is it a bad practice to include stdlib header file from a header file corresponding to the source file that needs that stdlib header?

If a file foo.cpp already includes foo.h, and foo.cpp requires some types from (for example, string.h), which is better, to include string.h in foo.cpp, or in foo.h ? For example, Guideline#9 in this ...
12
votes
2answers
1k views

Why does the base class need to have a virtual destructor here if the derived class allocates no raw dynamic memory?

The following code causes a memory leak: #include <iostream> #include <memory> #include <vector> using namespace std; class base { void virtual initialize_vector() = 0; }; ...
-1
votes
2answers
672 views

How to represent a directory structure in a binary tree?

I was just thinking about implementing a binary tree with its root pointing to the parent folder and then the children pointing to subdirs nested within to store a directory structure in a binary tree....
1
vote
1answer
93 views

How to efficiently access public static variables/methods of the correct derived class?

I have an arbitrary number of derived classes all inheriting from the same base class. These derived classes all have the same static variables and static methods, although the implementations may ...
0
votes
1answer
112 views

Is there a way to use and ignore blocks of code, caused by events during runtime?

I'm working in C++14 and trying to figure out a way to put two classes (with the same name) inside the same header file. In this scenario one class would always be ignored as a result of something ...
5
votes
2answers
208 views

How to track C++ class traits?

As a fan of regular types and value semantics, I'm keen on classes becoming more regular and being non-polymorphic. As a fan of non-throwing operations, I'm keen on operations being noexcept. I also ...
1
vote
1answer
795 views

How to pass integers between two C++ program using IPC

How do you pass a integer between two process. I'm new to IPC and using pipes I know how to transfer the string between two process. But how can I pass a numbers like that?. I can do this with the ...
6
votes
3answers
315 views

Should a high-performance API expose low-performance utility functions?

Context: I'm working on an open source project to solve a problem that comes up in ad-tech and social media data mining: indexing boolean expression trees, and matching them against incoming documents....
2
votes
1answer
105 views

Using the call stack as a stack data structure

Sometimes, I use the call stack as a data structure. I use local variables as elements on the stack and use the data member of a class to store the top element. When I use this pattern, I feel like I'...
-1
votes
2answers
101 views

Using std::move in Constructor with value error handling

Im confuesd about the usage of std::move in class constructors. I want to pass a value to a class and check in the constructor if a valid value is passed. If not an exception is thrown. Before i ...
5
votes
2answers
330 views

Debugging a slow process [closed]

I have a case where a bug takes more than an hour to manifest in debug mode (and still 20+ min in release mode). Does one know a debugging strategy which can help to reduce the waiting time until a ...