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.

-2
votes
0answers
10 views

end of file in c++ not working properly

When a beginner starts off reading ifstreams, his/her instinct is to read the file using a loop that usually looks like this: while (!ifstream.eof() { ... } However, when I used this code I noticed ...
-3
votes
0answers
18 views

Shell Script To Delete A File OS X [on hold]

Need to create a simple script to integrate within a Mac PackageMaker installer to delete a file. In the example below, the file to delete is test.file, and the full path is /Library/Application ...
1
vote
2answers
103 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 ...
2
votes
4answers
799 views

Is “Let more people able to review” a valid reason to “write c++ as if Java” at some degree?

According to Should we avoid language features that C++ has but Java doesn't?, I know it is horrible to write C++ as if Java, mostly because it drops the beneficial features of C++ languages. But ...
-3
votes
1answer
137 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 ...
6
votes
1answer
198 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 ...
-4
votes
1answer
65 views

Why is wchar_t in C++ implemented as a new data type? [closed]

I am learning C/C++ and have come across the type wchar_t, which appears to be 2 byte long char. So my question is why did C++ add a new type, when it could have just added the ability to apply the ...
1
vote
0answers
104 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 ...
-4
votes
0answers
39 views

extract function calls and arguments [closed]

I have a text written in c++ . I need to extract from it functions calls and their arguments. I used Antlr v 4 to write a small program but I just could get function definitions. my attempt My ...
-2
votes
1answer
84 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
1answer
55 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 ...
5
votes
1answer
332 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 ...
-2
votes
1answer
44 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 <...
-1
votes
0answers
30 views

What happens to a raw pointer member of a class foo smart pointer when the smart pointer is destroyed? [closed]

Say we have a smart pointer (std::unique_ptr) of class foo. This class has a raw pointer as a member. The program is executed and smart pointer foo carries out its intended functionality. If there'...
-2
votes
0answers
58 views

C++ code generation [closed]

I need to generate C++ code (headers and implementations). I would like to do it in C++ or C#. I can think of: Simply appending to string or writing to file directly Template-based approach (using ...
-2
votes
0answers
44 views

How to programmatically modify code in a Visual Studio C++ project [closed]

Let's say there's a set of actions I want to repeat every time I make a specific change to a codebase, for example I want to globally forward declare a newly created entity type for a video game, or I ...
-2
votes
0answers
46 views

How to auto populate 4 PDF's per truck load? [closed]

I have lets say 40 trucks of meat come to my Wearhouse every day, each truckload requires us to fill out 4 different PDF's that go 4 different places. The information is basically the same on each ...
0
votes
0answers
80 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 ...
8
votes
4answers
385 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 ...
-4
votes
0answers
37 views

I Don't understand this C++ run-time behaviour [migrated]

int main() { cout<< "Please enter your first name (followed by 'enter'):\n"; string first_name; // first_name is a variable of type String cin >> first_name; // read ...
1
vote
0answers
64 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. ...
3
votes
3answers
168 views

How to separate serialization, visualization and computation from GUI editable code objects?

This might be an X Y problem, but here's my situation. I've got a QT5 C++ code base whose task it is to allow for the configuration of a "process chain". A "process chain" here means a list of ...
12
votes
6answers
12k views

What is “using namespace” pollution?

I was looking at the google coding guide [here] and they do not recommend that one use the using namespace or namespace::function - if I did not misinterpret it. Does this apply to std as well? cout&...
1
vote
1answer
96 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
211 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
61 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 ...
0
votes
1answer
87 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 ...
0
votes
1answer
127 views

Inheritance and polymorphysm conundrum

Okay, I'm trying to write something resembling a 3D game engine. That means I have to deal with matrix transformations and similar stuff. For any of you who don't know, you need to use three basic ...
1
vote
2answers
97 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 ...
0
votes
3answers
199 views

What would be the downsides of creating a derived interface of interface?

Would there be any downsides of creating sub-interfaces for virtual member functions that have different parameter types? A drawing of this is shown in the image attached. Apple and Orange do not ...
1
vote
2answers
221 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
114 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;...
6
votes
3answers
430 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 ...
16
votes
3answers
1k 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
vote
1answer
95 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 ....
-1
votes
1answer
112 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 ...
7
votes
4answers
2k views

How can I have objects interacting and communicating with each other without forcing a hierarchy?

I hope these ramblings will make my question clear — I'd totally understand if they wont, though, so let me know if that's the case, and I'll try making myself clearer. Meet BoxPong, a very ...
2
votes
1answer
130 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
2answers
202 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 ...
0
votes
0answers
50 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 ...
5
votes
3answers
819 views

How to avoid two step initialization (C++)?

I'd like to follow the RAII(resource acquisition is initialization) idiom throughout my code but I'm also doing the template pattern where I'm developing generic versions of my classes and using them ...
1
vote
2answers
249 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:- ...
22
votes
6answers
7k 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
2answers
78 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 ...
5
votes
1answer
135 views

Optionally runtime properties

I’m looking for information on a pattern that I have used recently. The basic idea is that there is a type with a property that can either be compile-time (template parameter) or runtime (member). std:...
1
vote
0answers
15 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 ...
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 ...
7
votes
2answers
5k views

How to handle design changes for auto_ptr deprecation in C++11?

We are testing a library under C++11 (i.e., -std=c++11). The library uses auto_ptr and this pattern: Foo* GetFoo() { autoptr<Foo> ptr(new Foo); // Initialize Foo ptr->Initialize(...
10
votes
5answers
998 views

Is there a way to use gcc as a library?

Anyone knows a solution that works something like this: #include <stdio.h> #include <gcc.h> /* This .h is what I'm looking for. */ int main (void) { /* variables declaration (...) */ ...
0
votes
2answers
132 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<...