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

learn more… | top users | synonyms

0
votes
2answers
41 views

On a modern compiler, how do I intentionally code for 2s complement with wraparound?

I want to compare sequence numbers (given to this code from elsewhere) that may wrap around. Simply comparing two such values will not handle the case like 0x00000002 being greater than 0xfffffffd, ...
0
votes
0answers
13 views

Creating and passing new object in parameter

I have a wrapper class which contains a smart pointer (unique) which can point to objects which are subclasses of State. Each subclass of State receives a reference to the wrapper class so that the ...
1
vote
2answers
112 views

How to store state data when the data is related to another entity?

In order to increase the parallel-ability of my objects, I try to make them read-only and include only data that naturally belong to the entity. I have class Object { ... }; class Processor { ...
-6
votes
0answers
42 views

I have problem with code [on hold]

I should do massiv and The input of information from a text file into an array of records ; The addition of new elements to the end of the array ; To see all the elements of the array ; The ...
1
vote
2answers
140 views

Are there any alternatives to dependency injection for stateless classes?

I am working on an application whereby I have designed classes to fit into several groups: Immutable: initialised through constructors, uses copy-and-swap idiom (inc. move), can deep copy (i.e. ...
-1
votes
0answers
18 views

tidyParseBuffer strip the <style> tag in the body

When i use "tidyParseBuffer" function to parse a html, it remove the "style" tag in the body, usually the "style" tag should be in the head, but i need the contents in the body, what should i do to ...
1
vote
1answer
77 views

when writing platform specific code, is using separate .cpp always preferred instead of using #ifdef?

I have some platform specific code, such as a string needs different values at different platforms like it: test.cpp #if(PLATFORM==ANDROID) string url="android"; #elif(PLATFORM==IOS) string ...
2
votes
5answers
302 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 ...
-1
votes
0answers
49 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
101 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
76 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> ...
13
votes
7answers
1k views

Does C# experience translate well to C++? [closed]

My programming classes in school were C++, but I ended up working a job doing C# for the last few years. If there was a position that required say 1 or 2 years experience in C++, would my experience ...
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 ...
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 ...
18
votes
4answers
5k views

Debugging memory corruption

First off, I do realize this is not a perfect Q&A style question with an absolute answer, but I can't think of any wording to make it work better. I don't think there is an absolute solution to ...
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 ...
0
votes
1answer
53 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 ...
2
votes
2answers
86 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 = ...
4
votes
2answers
76 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 ...
9
votes
1answer
147 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 ...
1
vote
1answer
86 views

Client-Server app architecture with custom communication protocol

I am working on Qt/QML/C++ based Client-Server software system with custom protocol. Now, in both projects inside QtCreator I have same header and implementation files inside both projects. What is ...
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 ...
32
votes
10answers
3k views

The “blub paradox” and c++

I was reading the article here: http://www.paulgraham.com/avg.html and the part about the "blub paradox" was particularly interesting. As someone who mainly codes in c++ but has exposure to other ...
2
votes
0answers
63 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 {}; ...
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 ...
49
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 ...
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 ...
6
votes
5answers
362 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 ...
2
votes
2answers
186 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 ...
0
votes
1answer
276 views

C++, header files and using namespace std

So I understand that one must not use using namespace std; in header files. Well for my assignment we have to overload the >> operator. I got my program to run and all, but I had to include ...
5
votes
6answers
4k views

Template Functions and Function templates in C++

I came across a question which asked the difference between Function Templates and Template Functions in C++ and also Template Classes and Class Templates. I was under the impression that Function ...
2
votes
1answer
124 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
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 ...
17
votes
1answer
348 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 ...
4
votes
2answers
155 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
279 views

Feeding std::streambuf for Non-Blocking std::istream Read

I want to write small library to guide a child process for a specific needs (not trying to reinvent bicycle here). My needs includes reading from child stdout and stderr. I want to implement this as ...
-1
votes
1answer
150 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 ...
2
votes
2answers
221 views

Does it make sense to have a user specified thread limit?

I'm developing a C++14 application and would like to take advantage of the new multithreading features, in particular std::async. I have seen a number of applications which allow the user to specify ...
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 ...
101
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
204 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 ...
-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 ...
0
votes
2answers
108 views

The way to implement a configurable (at run-time) default style

I am coding a visualizer of graph algorithms. Each vertex of the graph has a style (color, size etc.). As long as the algorithm has done nothing to a vertex, that vertex has a default style. The ...
3
votes
5answers
395 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 ...
1
vote
2answers
85 views

Dynamic gesture recognition with fingertip points

I have built a fairly robust program in c++ which tracks several points on a hand. It accurately quantifies the size of the palm, the center of the palm, and the fingertip locations among other hand ...
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 = ...
6
votes
3answers
3k views

Is relying on implicit argument conversion considered dangerous?

C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones. A very basic example ...