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

learn more… | top users | synonyms

-1
votes
1answer
36 views

Designing an application with safe paralleled tasking

The title may have been a little vague... I am working on a piece of software that is designed to perform one task. I would like this task to work in parallel, allowing for multiple asynchronous ...
0
votes
6answers
232 views

Dealing with a variable that is a number, but has greater meaning? [on hold]

I've been working on some embedded code that handles a Bluetooth Low Energy (BLE) radio. BLE has 40 channels, numbered 0 through 39. One function for the radio driver takes in the channel and sets ...
-2
votes
0answers
67 views

Text file - editing in C++ [on hold]

I have some lines of text in a word doc. Each line has the format of an article, like: Author(s). Title. Journal, number of the Journal (Year), pages I want to put this data in Excel but in way such ...
0
votes
1answer
51 views

Preprocessor and double declaration include in different files

I am wondering how compiler (or preprocessor) include headers. I have three files. First is header.h, second first.cpp <- and there is #include <iostream>, third <- it contains #include &...
18
votes
3answers
2k views

How to handle failure cases in C++ class constructor?

I have a CPP class whose constructor does some operations. Some of these operations may fail. I know that constructors do not return anything. My questions are, 1) Is it allowed to do some ...
4
votes
3answers
169 views

Which is the best design for callback implementation in C++?

I have a class "Parent". "Parent" class creates an object of class "Child" in my CPP module. The use-case is "Child" has to request for some information from "Parent". This can be done in several ways ...
1
vote
1answer
100 views

Why did DirectDraw allow developers to directly write to GPU VRAM?

I'm reversing an old DirectX 7 game and I noticed that it sometimes uses Blt and BltFast but at other times, it locks the directdraw surface and directly writes to GPU VRAM. Why did developers take ...
4
votes
1answer
77 views

Compiling for string and wstring

I'm creating a library. I want to use it in multiple projects which may use multi-byte or unicode (std::string or std::wstring). I've adopted the old MS method of conditional compiling: namespace ...
2
votes
3answers
150 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
2answers
148 views

passing by refernce

I am study c++ and c languages, i was writing in javascript before. Im trying to understand the ideas of pointer and refernces. So im stuck with following, what would be the specific behaviour in this ...
1
vote
2answers
317 views

Using a domain name as C++ namespace

What would be a good system to use domain names as C++ namespaces in order to avoid name clashes between developers? The idea appears to be popular in the Java world. We cannot use namespace example....
-2
votes
0answers
69 views

TicTacToe Project [on hold]

I am building a TicTacToe project on C++. I am using array to define the TicTacToe board. I was wondering is there a much cleaner way to define the board instead of using 2d array.Please suggest me if ...
-3
votes
0answers
29 views

Why can't I debug this in code::blocks? [migrated]

I have the following program and I want to debug it. #include <iostream> #include <cstdlib>> using namespace std; void display(char charArray[], int SizeOfArray); int main() { char ...
-4
votes
0answers
109 views

Big Projects in C++ [on hold]

After so much digging, i am asking THE question which is on my mind from almost an year. Just look at this list List of c++ softwares 10 best c++ softwares My question is, How these are ...
-2
votes
1answer
106 views

What is a good OS for getting maximum performance out of a C++ program? [on hold]

I am looking to run a C++ program without any interference (context switching) from other processes. Is there a small operating system that will allow me to stop all other processes? Is there a bare ...
0
votes
0answers
90 views

How to fit a gaussian curve to data for a goodness-of-fit C++? [migrated]

I've given a dataset of N samples like: (x,y) (-100,1), (-90, 30), (-50,60), (-10,90), (0,100), (10, 90), (30, 20),(100,4) Now I would like to determine how well the data fits a perfect gaussian (...
3
votes
1answer
66 views

Pitch/Time Shifting of a PCM byte array

I am searching for a universal algorithm that shifts pitch and time while keeping the sample rate. (I am trying to program a sound generator (sine, triangle...) as an exercise) I just want to squeeze ...
3
votes
5answers
979 views

How does bitwise information storage in (32-bit) int variables work?

In this book I'm reading I'm going over bitwise operators. Its says the following in the book. Bitwise operations can potentially store a lot of information in a small amount of memory. Many ...
1
vote
1answer
68 views

How can I filter my coordinates system?

Following up with this, I have a bunch of coordinates and I draw them on a bitmap image as a coordinate system. Now, I would like to get rid of all the noise, and filter coordinates to give a "clearer"...
0
votes
1answer
74 views

Are there system calls like posix in assembly level using int number for windows

I want to write assembly program using windows syscall Interrupt number , so in order to use system call in assembly level using int of sys call, In windows are there kernel calls like posix ...
0
votes
2answers
68 views

Getting a stateless time-based index out of overflowing timer

I'm currently working on an Arduino project where I need to keep track of entries for a certain amount of time, in this case, 30 days. Our company will attempt to sell this product to cities and ...
-2
votes
0answers
59 views

Do I need a commercial license for Qt if I'm going to sell on the Mac App store?

I would like to build an os x app and sell it on the Mac App Store. I'm going to build this in C++ and use the Qt library. I'm wondering if I can use the free version or if I need a commercial license....
2
votes
3answers
112 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
2answers
100 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
202 views

Design classes to prevent future code breaks

I'd like to design a robust version of this class (C++11): class Oscillator { private: std::vector<double> trajectory_; // Some numbers that are needed to get the trajectory ...
83
votes
7answers
21k views

Why declare a variable in one line, and assign to it in the next?

I often see in C and C++ code the following convention: some_type val; val = something; some_type *ptr = NULL; ptr = &something_else; instead of some_type val = something; some_type *ptr = &...
4
votes
3answers
556 views

Avoiding constructors with many arguments

So I have a factory which creates objects of different classes. The possible classes are all derived from an abstract ancestor. The factory has a configuration file (JSON syntax) and decides which ...
1
vote
6answers
207 views

Short circuit evaluation is C++? [duplicate]

I've been reading the C++ for dummies book and I'm loving it! I'm on the section where he is talking about short circuit evaluation. Here is my understanding of short circuit evaluation. Short ...
2
votes
5answers
449 views

Why isn't byte | bit the only built in data type?

All languages I have seen so far have multiple builtin data types (int, double, float, char, long...). But if we look closely, they are just arbitrary arrays of bits, the only difference between them ...
18
votes
7answers
9k views

Is it a good practice to use smaller data types for variables to save memory?

When I learned the C++ language for the first time I learned that besides int, float etc, smaller or bigger versions of these data types existed within the language. For example I could call a ...
1
vote
3answers
127 views

Unlike C++, why does uncaught exception in JavaScript not terminate the script?

As someone used to C++ and new to JavaScript, I find this behavior odd. Whether a program runs directly on the platform like C++ ones, or it runs at a higher (or deeper?) level like JavaScript ones, ...
0
votes
2answers
185 views

Compiling source code using c++

Last year, in university we used the library SDL to create a game from scratch. So I though of developping a game engine based on SDL. I will be using Qt to do the UI and SDL to implement the core of ...
-2
votes
1answer
90 views

C++ Loop object “pairs” with one in common

I could not think of a better name. I have a class called MoveObjects which holds position and move info. Then I have two classes, Items and Attacks. Both have MoveObjects in common. What I am ...
-1
votes
3answers
139 views
6
votes
3answers
568 views

How to properly deal with starvation

I'm trying to find a way to avoid starvation in my program, a producer/consumer (two threads, one for each role) problem with four priority levels (four deques). Basically, the consumer thread always ...
1
vote
4answers
371 views

Why does C++ have auto, rather than simply doing the right thing when there are no explicit type declarations?

When auto was considered for addition to the C++ standard, was there any discussion of setting implicit types where there are no explicit declarations? And if so, was the discussion recorded anywhere?...
12
votes
6answers
521 views

Idiomatic usage of exceptions in C++

The isocpp.org exception FAQ states Do not use throw to indicate a coding error in usage of a function. Use assert or other mechanism to either send the process into a debugger or to crash the ...
-4
votes
0answers
93 views

High performance Inter Process Communication (IPC)?

Apologies if this question is "off-topic", I hope it's not... I'm looking for an IPC technology that is capable of communicating to processes on other machines, as well as on the same machine, with ...
0
votes
3answers
130 views

Is there a compiler switch changing the scope of variables in loops? [closed]

I'm using some code, which uses variables declared in a loop after the loop. For example for (int i = 0; i != 10; i++) { // do stuff } int x = i; I get the "i" undefined error. Is there a ...
3
votes
1answer
86 views

Regarding the Organization of Bit Shifting Utility Functions in C++

I am developing a project in C++ that deals with converting an ASCII hexadecimal string representation into binary. The class also has utilities in it for extracting info from the string. Right now ...
-1
votes
0answers
19 views

Faster determinant from LU decomposition of a matrix represented as 1D array?

I have this working algorithm to find the LU decomposition in place of a matrix (Stored as a 1xN*N array), and it works well, however I'm curious if anyone knows a way to quickly get the diagonal ...
0
votes
1answer
115 views

Getting an array index (0,1,2,..8) from bit masking value (1,2,4,8..256) without using log2(n). Maybe a design issue

I'm working on a component where I put in data and I get different data as a result. The input is always the same (3 Objects). From these 3 Objects up to 9 other Objects can be calculated. One ...
0
votes
1answer
105 views

Inject several objects in C++ ctor

I'm looking for a good way to somehow dynamically inject several objects to main class and adjust its method by calls of these dependencies, e.g. ComponentClass1 { updateSmth1(); }; ...
8
votes
6answers
6k views

Why do we put private member functions in headers?

The answer to why we put private member variables in C++ headers is that the size of the class must be known at points where instances are declared so that the compiler can generate code that ...
5
votes
3answers
308 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
465 views

gtkmm manage/add vs smart pointers:

gtkmm provides lifetime management of widgets using Gtk::Widget* aWidget = Gtk::manage(new Widget()); Gtk::Widget.add(*aWidget); This delegates lifetime management of aWidget to its container ...
0
votes
2answers
147 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 ...
9
votes
5answers
437 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 (...) */ ...
2
votes
2answers
123 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 ...
6
votes
4answers
376 views

How can I effectively use one file per class in C++?

Even though I have a decent bit of professional experience with object oriented programming in Java and a basic familiarity with C, I've run into a bit of a mental block with C++ that I was hoping ...