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

learn more… | top users | synonyms

-1
votes
0answers
41 views

Integrating IDE with docker C++ toolchain

I have created a docker in order to compile C++ applications using a third party toolchain. My ideal work environment would be to leave the sources on my local directoy and to use the docker only for ...
-4
votes
0answers
94 views

How to add multiple numbers in C++? [on hold]

I learnt that we can declare multiple 'int's in C++ by typing something like int n[30]; and it can be done instead of typing int n1,n2,n3,n4,...............n30; Q1: I have a doubt if it is ...
0
votes
1answer
74 views

What data structure to use to save the address of edges in depth first search?

I am currently trying to write my own Depth First Search. I have created a class called node. class node{ private: bool is_visited; <data structure to collect edges> ...
0
votes
0answers
27 views

I am trying to make a function with that returns true/false if an element is in the vector but I am getting an error? [migrated]

I am trying to implement a function in C++ using STL which takes an object and a vector of objects and return true if the vector contains the object else false. Below is the implementation of the ...
2
votes
5answers
282 views

Why do I need to declare virtual functions as such?

Example: We have a base class Base and three subclasses which all implement their own version of doSomething(). In an intermediate function f(Base b), we want to call the relevant version of ...
0
votes
2answers
40 views

Best Communication strategy for monitoring dashboard

I have a requirement where I need to display certain stats on Admin Dashboard in my web application (Angular+Java). These stats (transnational data) are being generated on different servers (connected ...
2
votes
2answers
83 views

C++ vs Java: Pointing to Objects

In Java: private State current_state; As "State" is a superclass, I can then assign subclass objects to current_state, effectively making current_state point to a different object: current_state = ...
0
votes
1answer
49 views

How to traverse “linked list” like structure with parallel nodes

I am working on a signal processing project that allows for parallel processing on data streams as well as inputs and outputs to and from multiple endpoints. The signal chain is broken down into ...
4
votes
2answers
74 views

How to facilitate thread-safe access to large set of shared variables?

I have 2 sets--inputs and outputs--of 70 32-bit integer variables and 70 bools (140 vars altogether). These need to be accessed and modified from 3 threads. What is an appropriate design pattern to ...
2
votes
1answer
34 views

Configuration related defines in public header?

Suppose you're building some library, C or C++ doesn't really matter for this question, IMO. The features (or implementation thereof) depend on capabilities of the target system. A simple, probably ...
2
votes
0answers
60 views

How to combine template and inheritance

I have multiple factories, each is responsible for creating instances of an inheritance tree. For example (syntax or semantics maybe incorrect), struct InterfaceA {}; struct ImplA1 : InterfaceA {}; ...
-3
votes
0answers
44 views

Compiling C++ on windows [closed]

This is my first time posting something up there so any advice would be good. (I'm not a native english speaker, so i may be difficult to understand from time to time, don't hesitate to point out my ...
4
votes
2answers
135 views

Passing readonly structs in C++

In this particular problem I am having, I am not sure of the proper way to deal with readonly structs, passed to class constructors as a parameter when I want to store the data in the struct, in the ...
0
votes
0answers
28 views

Help me understand this flow for recursive function [duplicate]

This recursive function blows my mind a bit because it executes the recursive calls until it hits 1. It returns n, but afterwards it does the multiplication below it four times and returns the final ...
2
votes
2answers
185 views

In C++, why shouldn't all function parameters be references?

I am currently learning C++ from the C++ Primer 5th edition. The book's chapter on functions states that only large objects (large being relative as standard library strings count, but "primitive ...
48
votes
10answers
11k views

Why would the 'final' keyword ever be useful?

It seems Java has had the power to declare classes not-derivable for ages, and now C++ has it too. However, in the light of the Open/Close principle in SOLID, why would that be useful? To me, the ...
1
vote
1answer
102 views

Static memory idiom

I am on a micro controller (which means I can only have static memory allocation) and I am trying to work with inheritance..... Suppose I have a abstract class Image and an abstract class Font. An ...
4
votes
2answers
154 views

Why does ifstream.eof() not return TRUE after reading the last line of a file?

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, C++ programmers note that what ...
2
votes
1answer
121 views

Fine tuning details in C++ function for different customers

The company I work for follows a business model where a core product exists (originally written in C, now in C++) with some default implementation but details are tailor-made for each customer (there ...
-1
votes
1answer
149 views

What is the faster way to save and browse objects using vectors +/or maps? (c++)

I'm doing a object Garbage class using c++: #include "Object.h" class ObjectGarbage { public: ObjectGarbage(); ~ObjectGarbage(); void Call_All_Objects() { ...
4
votes
2answers
118 views

Calling different library functions based on parameter

I am writing a rather large class where the user can specify at runtime whether she wants to use algorithm A or B of an third party library e. Basically there is only one function call different in ...
16
votes
1answer
344 views

How does Rust diverge from the concurrency facilities of C++?

I am trying to decide whether Rust fundamentally, sufficiently improves upon the concurrency facilities of C++ that I should spend the time to learn Rust. In light of Stackexchange's format, I should ...
9
votes
1answer
145 views

Idiomatic wrapping of C++ template type API in C

I'm working on wrapping a C++ API which provides access to a data store (Hazelcast) in C functions, so that the data store can also be accessed from C-only code. The Hazelcast C++ API for the Map ...
0
votes
2answers
62 views

Method to mask variable names in C++ files (cpp, h) and create an intermediate API?

I have a project which involves using C++ files along with an API on a local PC to communicate with a remote server app, and for sake of maintaining a semblance of non-disclosure with any hired ...
1
vote
2answers
36 views

Are Data defined into derived class saved when up-casting?

Let's say i have two class named Object (base class) and an actor class (derived class). The actor class uses physics so i need to implement it on the Actor class. But there are other derived class of ...
1
vote
1answer
24 views

How do you achieve the 'BST Property' in a Template Binary Search Tree?

We recently started learning about binary search trees. We created one of our own using integers as our Key/Data. It's easy to achieve the BST property using an int key, but what happens when we ...
5
votes
5answers
359 views

Is it wise to rely on optimizations?

Should I write my code to be clear what I am doing and rely on the optimizer to clean up my code efficiency, or should I be obsessive about getting every last ounce of power out of my code? And how ...
-3
votes
0answers
22 views

Keyboard input errors while running [migrated]

I'm having issues with a program that was originally written in Visual C++ 6.0. The program builds and runs fine, until I attempt to enter values into the command line. I believe that I have isolated ...
99
votes
4answers
10k views

Does a `long` ban make sense?

In today's cross-platform C++ (or C) world we have: Data model | short | int | long | long long | pointers/size_t | Sample operating systems ... LLP64/IL32P64 16 32 32 64 ...
2
votes
2answers
200 views

How does long long syntax work when int int doesn't in C++?

I was wondering if long long specifies a single datatype then why don't things like int int work? I meant obviously that's not a data type but there is a long data type. Essentially what I'm asking ...
0
votes
0answers
17 views

Unexplainable bug in my code [migrated]

So I'm trying to write a small application that changes a line in registry to enable a certain thing.. Here is my code. #include <iostream> #include <Windows.h> DWORD transparenton = ...
2
votes
5answers
388 views

What is the best way to save data of a C++ Program ? Binary vs JSON serialization

We are implementing a CAD program (in C++, Qt) where we have interdependant classes : The smallest brick is the Pattern, it is just a distribution of points. Then we have Layouts which contain ...
2
votes
0answers
82 views

What are the benefits of an input/output component design?

For the company I work at, all of our projects, including a new one started last year, are written in C89. We write for vxWorks (a real time embedded operation system). Our software runs ...
2
votes
1answer
161 views

How does this C++ assignment work?

I have very limited experience with C++ but I do have plenty of experience with Java and NodeJS. I've decompiled and tried to make sense of a small C++ compiled file and I've come across something ...
0
votes
0answers
83 views

Building a heap in C++

I am learning heaps in C++ and I have a question about heapify function. So in order to build a heap from a random array, you put the elements from the array in a binary tree in order in which they ...
1
vote
1answer
78 views

Get or infer template type from inherited member

So I have an assignment from college where I have to apply multiple metaheuristics to different problems. I thought that I should make everything as modular and reusable as possible to reuse ...
3
votes
4answers
232 views

When should a function take a pointer for a collection to fill vs returning a pointer with a filled collection?

In C++ I frequently see these two signatures used seemingly interchangeably: void fill_array(Array<Type>* array_to_fill); Array<Type>* filled_array(); I imagine there is a subtle ...
4
votes
1answer
135 views

Word ladder efficency problem

I have a problem dealing with word ladders. The problem is: given two words and a dictionary file, find the shortest word ladder between the two words. So if given the words cat and pot: cat -> ...
0
votes
0answers
7 views

Can't find a source file […] allocator.h [migrated]

I am trying to debug a debug example code, which is part of a C++ course materials, with Eclipse. However, once a certain line of the code is reached, this message is displayed and the the rest can't ...
0
votes
2answers
124 views

Naming when having to inherit classes [closed]

I am always a huge fan of standards and think I finally decided on one of the many C++ naming standards. However, it almost seems moot because working with a couple of libraries where the standard use ...
0
votes
1answer
112 views

CreateFileMapping() - parameters of size

I want to make a program, which will put some sentence in shared memory so another program will receive this massage. I made that, but I do not understand the 4th and 5th parameters of ...
2
votes
0answers
55 views

Default move assignment and destruction order of members versus the rule-of-zero

Members must frequently be destroyed in the correct order. As member creation is in forward order and destruction is in reverse order this will usually work fine. However, when assignment operators ...
2
votes
1answer
82 views

What is MISRA 8-0-1 rule on init-declarator-list and member-declarator-list about?

I am reading company's coding guidelines, and I encountered the MISRA 8-0-1 rule, which states: An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or ...
2
votes
2answers
323 views

Could someone write an opensource version of the Windows API?

I am wondering if it is both possible and how one would write an opensource version of the Windows API. What I mean by this is, say you #include <Windows.h> in your C++ application. Then you ...
1
vote
2answers
74 views

Implementing an event scheduler for animations

The basic idea is to have some animated widgets that sit in a container, quite similar to Qt (the only actual difference is that my widgets are animated). The animation is in some cases dependent on ...
4
votes
2answers
127 views

Design question about hiding implementation from users of a dynamic library

I'm building a DLL and in my public headers I have this: (definitions are in .cpp but for clarity I show them in .hpp here) ObjectTag.hpp: class API_DLL ObjectTag { public: ObjectTag() : ...
1
vote
3answers
318 views

Do I have to fork a server program as an “C” child process in order for correct interprocess communication to take place?

I would like to implement interprocess communication between an Ubuntu Linux 15.10 mono 4.1.2 C# recorder client and Ubuntu Linux 15.10 mono 4.1.2 C# video server using a C++ mutex class and C++ ...
1
vote
1answer
142 views

Does having so many macros (#define) increase compilation time due to prolonged pre-processing?

In a very simplistic way, I understand: "Compilation" = "Pre-processing" + "Parsing" + "Linking" + "Executable" All the macros and other such pre-processing directives are taken care at the ...
1
vote
2answers
176 views

Why doesn't the compiler complain when I try to access a non-existent array value?

My C++ book says that if I have int anArray[25]; and I try to evaluate anArray[25] = 0; the program will simply overwrite whatever value is stored in the next memory address past the end of the ...
0
votes
0answers
71 views

Arbitrarily sized (and signedness) integer arithmetic in C++ - How can it be done generically at runtime?

How can I efficiently handle integers of unknown size and signedness in various arithmetical operations in C++? (for a virtual machine). I am storing the program for the virtual machine in a string ...