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.

0
votes
0answers
54 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
85 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
211 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 ...
22
votes
6answers
8k 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
23 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
252 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
113 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
134 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
67 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 ...
1
vote
2answers
218 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
83 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
93 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
157 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
238 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
93 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 ...
8
votes
2answers
370 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
235 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
80 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
166 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
294 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
311 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
101 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
93 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
157 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 ...
0
votes
2answers
104 views

Should I always allocate QObject and derived classes to the heap?

I was in #Qt irc channel, and I showed a small snippet of my code in a style that I heavily rely upon. It looks like this: /* Get Reply from Server */ QPointer<QNetworkReply> reply; { ...
14
votes
7answers
6k views

Is it a bad idea have make a class method that is passed class variables?

Here's what I mean: class MyClass { int arr1[100]; int arr2[100]; int len = 100; void add(int* x1, int* x2, int size) { for (int i = 0; i < size; i++) { x1[i] +...
0
votes
1answer
38 views

Processing data in a cluster with multiple tasks

The goal is to provide a scaleable system implementing multiple data processing tasks which can be seen as a graph. Data objects will travel that graph. Most object will visit the same nodes in the ...
11
votes
1answer
497 views

Using friend classes to encapsulate private member functions in C++ - good practice or abuse?

So I noticed it's possible to avoid putting private functions in headers by doing something like this: // In file pred_list.h: class PredicateList { int somePrivateField; ...
0
votes
2answers
162 views

What are the advantages of proxy classes?

I've been learning about proxy classes in c++. I really don't see the advantages of using proxy classes, as they're not any better at concealing information than private members are. What advantages ...
2
votes
2answers
125 views

Primitive type conversion in computer graphics

I have been repeatedly told that explicit type conversions are an indicator of bad code and they should be avoided. Now in all honesty I have been annoyed a bit by these claims due to the nature of ...
0
votes
1answer
66 views

Is it better to initialize semaphores in shared memory or give them as command line arguments? (C++)

I am on a project for which I have to spawn many different processes, all in different executables, and there will be some shared memory segments and some semaphores to synchronize them. I use an "...
-1
votes
1answer
111 views

How to organize the build system of a project as it starts including multiple languages across multiple operating systems and compilers?

I wrote a Music Player and Library in Java for GNU/Linux and Windows. My build process is currently in ANT, but I intend to migrate away from that to something more modern after the next release. I'...
7
votes
2answers
386 views

Class that returns multiple unrelated values, are there better way to accomplish this?

I have a "tracker" class. This class tracks objects from a given input image. But in addition to this, there is another parameter that corresponds to a value used in generating the image. The ...
5
votes
3answers
1k views

Is it okay to start a thread from within a constructor of a class

This is purely a design philosophy question in the context of C++. Is it a okay design philosophy to start a thread from within a constructor? I have a library whose sole responsibility is to ...
1
vote
1answer
125 views

How to understand and design functions with enumeration arguments that work in tandem with bitwise operators in C++ and Qt?

In the C++, there are 6 bitwise operators: Symbol Operator & bitwise AND | bitwise inclusive OR ^ bitwise XOR (eXclusive OR) << left shift >> right shift ~...
4
votes
1answer
114 views

Should I specify my header include path in the source code, or as a project option?

Basically, I am asking, whether my code should say #include “../libs/src/my_lib.h” or #include “my_lib.h” with a complier option of -I ../libs/src/ I feel (reasonably strongly) that ...
3
votes
2answers
292 views

Include own header file first or last? Any technical reasons?

I was revisiting my question How can I prevent header hell?, when I noticed a comment which said A good technique for ensuring a header is independent is having a rule that the source file always ...
-4
votes
1answer
108 views

Inheritance of Constructors from parent into child class [closed]

Is the Default Constructor of Super or Parent class Can be Inherited into Child class ?
0
votes
1answer
182 views

Is it a good idea to make huge objects dynamic in C++? [closed]

I have an engine and if I want to use the 3d system I always have to pass a pointer to any mesh renderer. If I would make the 3d system static then I just could use them. But the 3d system is big with ...
3
votes
3answers
197 views

Factory pattern or builder pattern ? which one is suited for reading Finite Element Model data from a text file?

A follow up to another question (Making a design decision about reading model data from an input file). I wish to ask another question regarding builder or factory pattern. (I read that builder is ...
1
vote
1answer
242 views

Best practice of c/C++ dependency management on build servers?

I develop largely in java which has maven or ant/ivy. Is there a recommended way to manage build dependencies for c++ projects? I'm setting up the build on our build server right now but the thing ...
2
votes
1answer
94 views

Making a design decision about reading model data from an input file

I am writing a finite element software in C++ and Qt. I want to load the input data to the model. I have a Model class that holds the data and does the work. I have created a simple lexer and parser ...
2
votes
1answer
169 views

What are the pros and cons of keeping most of an application's state in a single struct?

In my application, I have a few classes. Many of these classes share common state like a reference to the logger for example. For example, both A and B require some common state to get their job done. ...
5
votes
3answers
283 views

Does the output of a compiler depend on the OS you are using?

In the company I am working in we have a management software, written by an external programmer. Let's call the software PK. PK was initially written in the 90s using C++. Since then it was regularely ...
1
vote
1answer
71 views

Managing a third party library that is used by multiple independent libraries

I am working on configuring the build environment for a C++ project that uses multiple libraries. These libraries are independent of each other, but they all depend on the same 3rd party library (...
0
votes
1answer
373 views

C++ naming convention for files within namespaces

I am currently working on a C++ project with a source file structure like this (headers excluded): src/ ├── namespace1/ │ ├── namespace1_base.cpp │ ├── namespace1_derived1.cpp │ └── ...
2
votes
1answer
226 views

Architecture for messaging library C++

I have a library, which sends and receives a set of binary messages and parses them. So far I’ve used inheritance for my design, i.e. class BaseMsg { // init msg from rx'd binary stream ...
3
votes
2answers
462 views

C++ Gof Design Patterns heavily depends on new or shared_ptr

I'm trying to learn the best practices for code design and reuse in C++ so I am going through the well known GoF Design Patterns Elements of Reusable Object-Oriented Software. I noticed that nearly ...
3
votes
4answers
206 views

Inheritance: When only some concrete objects need to share state

I have a series of classes that represent widgets in a layout system. The base class for all of these concrete widget types is Widget. If I have a Button and a Text Box, these both derive from Widget. ...