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

learn more… | top users | synonyms

-3
votes
0answers
17 views

Segment sieve of Eratosthenes code

I got this code to print prime number between m and n and while doing its dry run ,i observed that even if prime is not set to be 1 for composite 4 it gives same result int main(int argc, char** ...
3
votes
0answers
35 views

What is the correct place to put checking of conditions in this use case?

Here is the situation: I have a database and a class that is basically a representation of a set of fields of different tables in it. Let's call it Message. "Message" does not know of the database ...
3
votes
2answers
116 views

Are string characters assigned a numerical value in context of how they are assigned in a programming language?

For context I am fairly new to programming after returning back to it after programming a number of years ago... I was reading Bjarne's intro programming with C++ and was wondering if alphabetical ...
-3
votes
0answers
20 views

How to use fftw in Qt [on hold]

Could anyone explain how to use the library fftw 3.3.4 in Qt5.4.2, please? I have looked for some examples on the internet and followed them. But it didn't seem worked to me. Thanks a lot for any ...
-4
votes
2answers
149 views

Is it possible to learn C++ on the fly? [on hold]

I am reading books and doing the examples that the book has to offer. Often times, I find myself getting bored b/c t.b.h it's basically stuff that doesn't really interest me much. Don't get me wrong, ...
3
votes
4answers
147 views

Design: Lisp (or other scripting language) as an interactive interface for C++?

I'm working on a medium size C++ project (will probably end up around 50k lines) and I have to provide an interactive terminal interface. The program produces scientific data as an output and the ...
0
votes
1answer
63 views

A secondary “type system” for references?

I'm designing a language and was wondering how to incorporate C++-like references with regards to their place in the type system. I think they're useful for operations like indexing and dereferencing ...
2
votes
3answers
389 views

How to manage focus for a small set of simple widgets

I'm developing a set of simple widgets for a small (128x128) display. For example I'd like to have a main screen with an overlay menu which I can use to toggle visibilty of main screen elements. Each ...
13
votes
10answers
1k views

Does low latency code sometimes have to be “ugly”?

(This is mainly aimed at those who have specific knowledge of low latency systems, to avoid people just answering with unsubstantiated opinions). Do you feel there is a trade-off between writing ...
-1
votes
0answers
84 views

How to compare numbers in a file? [on hold]

What I would have to do to search a file (file.txt for example), and compare its values with the ones I'm asking the user to input. There will be numbers in the file already(production orders) and i ...
0
votes
0answers
41 views

Only one case of base class function member executing on derived class object [migrated]

I have a derived class Circle of base class Shape, where each class has its own print, collide, merge, type, etc functions. I instantiate a bunch of Circle objects and put them into a container (its a ...
1
vote
1answer
69 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 ...
-1
votes
0answers
19 views

Error in c++ code -Templates [on hold]

I get an error in this following code.where is the error in this following code.and please explain a bit. template<class T1,class T2> T1& MinMax(T1 t1,T2 t2) ...
4
votes
1answer
468 views

Is it poor form to use C features such as the size_t type instead of their c++ counterparts, such as std::size_t?

I have recently been told that using size_t as declared in the global namespace is incorrect in C++, ostensibly because size_t is a C-feature. I looked this up and came across this question on Stack ...
-4
votes
0answers
36 views

Windows custom lockscreen program [on hold]

I'd like to create a windows application that locks my screen, I want the program to have the same functionality as this program but I want to add functionality to it so I can play custom sounds and ...
2
votes
1answer
143 views

What would be a reason not to embed JS in C? [on hold]

I'm working on an opensource application that processes JSON in C, because I would like to make it easier for people to help me in the project and because JSON is so close to JS. I want to embed a JS ...
0
votes
0answers
23 views

What is prerequisite for Algorithm and Data Structure Analysis and Designing [closed]

I want to learn Programming, So I want to start this learning program with studying of the Introduction to algorithms book. I'm familiar with C, C++ and ASM Language a little bit, but I can't write ...
1
vote
0answers
55 views

Pointers vs IDs for “context-specific” functions

I need to be able to load, use, and free resources from a single monolithic object. I have two requirements: 1. That the resource loaded is owned by the object that created it and 2. All objects in a ...
-1
votes
0answers
24 views

Best use of Winpcap [closed]

I just need to know the best/most efficient way to use winpcap to monitor 5 different tcp ports while another program is running displaying the data etc. I was using a thread for each port with a ...
0
votes
2answers
612 views

Is factory pattern a right pattern for the situation described here?

Is factory pattern a right pattern when we want to consolidate the related objects? Problem - In the Set-top box, I have a user-io, basically the interface to control the settop box - The user-io can ...
-3
votes
0answers
27 views

How to compile Selenium on Debian Jessie, failing on ibus [closed]

When I compile Selenium on Debian Jessie, it gives me this output. I have ibus lib installed. I think that I use different version. I am right, how can I solve it? If you need to provide any ...
83
votes
14answers
12k views

Does auto make C++ code harder to understand?

I saw a conference by Herb Sutter where he encourages every C++ programmer to use auto. I had to read C# code some time ago where var was extensively used and the code was very hard to ...
2
votes
2answers
156 views

Is it bad practice to use constant variables with global scope in C++?

So I was reading section 3.2 (One definition rule section) in the latest working draft of the C++ standard and came across this: Every program shall contain exactly one definition of every ...
-1
votes
0answers
24 views

Dijkstra algorithm with pair [closed]

int dijkstra(){ memset(visited,false,sizeof visited); priority_queue< pair<int, int> > Q; for(int i = 0;i < A;++i) Q.push(make_pair(0,X[i])); while(!Q.empty()){ pair<int, ...
-1
votes
0answers
39 views

Is there any way of doing if/while assignment in Visual Basic? [closed]

For example, in C/C++, you can do the following: #include <iostream> #include <conio.h> int main() { char c; while ((c = getch()) == 'f') { std::cout ...
2
votes
1answer
192 views

How often should RAII be used? [closed]

I've been attempting to learn C++, but it is famously plagued by bad tutorials. I learned about a clever little trick called RAII (Resource Acquisition is Initialization), where one wraps a heap ...
6
votes
5answers
1k views

C++ Iterators: Best practice to represent end of range - Last or Beyond-last?

I am writing a library which deals a lot with sub-sequences of ordered containers. So for example I have a container (1,2,3,4,5,6) and a user wants to access (3,4,5). I am providing the subsequence ...
0
votes
0answers
72 views

What's stopping “After Effects- like” apps from being developed in the browser given ASM.js [closed]

Given asm.js are there any significant technical reasons stopping an app like adobe's after effects in the browser? I'm aware that it would probably be a massive task, but from a purely technical ...
4
votes
2answers
98 views

C++ design for encoder/decoder classes with different stored types

I need to handle different elements in a vector, each element owning a specific parameter (integer or string), so that I can easily handle encoding/decoding of a series of elements. Encoding a list ...
0
votes
4answers
198 views

How to write procedural code in an object oriented language?

I recently started working in domain of mesh generation . My programs usually contains large chunks of procedural code consisting of several phases. Eg. class MeshAlgo1 { /* A very long function ...
9
votes
4answers
2k views

rand() gives same numbers again for a small range

I'm trying to make sort of a game where I have a a grid of 20x20 and I display a player (P), a target (T) and three enemies (X). All these have an X and a Y coordinate which are assigned using rand(). ...
-4
votes
0answers
22 views

My code compiles, executes, but crashes for certain inputs [migrated]

I am trying to get the length of longest common subsequence for two strings. It works for most of the inputs but it crashes for the input specified. The code is as follows: #include <cmath> ...
0
votes
2answers
145 views

Are private members useful anymore? [duplicate]

Watchpoints and data break points make it possible to watch the changes of a value in memory in many languages. Much of the justification I have seen for getters and setters and private variables ...
8
votes
6answers
1k views

Coding style issue: Should we have functions which take a parameter, modify it, and then RETURN that parameter?

I'm having a bit of a debate with my friend over whether these two practices are merely two sides of the same coin, or whether one is genuinely better. We have a function which takes a parameter, ...
1
vote
0answers
56 views

Data sync local LevelDB store with server? [closed]

I'm building a cross platform application in C++. I need to have local JSON data storage that is syncable to a server. LevelDB seems like it could fit the bill. There is a Node module ...
5
votes
2answers
759 views

Is there a standard way to indicate that a function returns a new pointer?

Sometimes I want to delegate the construction of objects that a class owns to a separate function. Something like Vertex* new_vertex(const Options& options) { // do stuff... return new ...
5
votes
2answers
127 views

How to setup build system for unit testing + mocking?

We have a legacy code base in entirely C++. Our build system is CMake. My first stab at unit testing was as follows: Define a target (LibraryA). This library contains the code to test. Define a unit ...
2
votes
2answers
158 views

Blocking function call with asynchronous content

I am sure that this is a common design pattern, but I seem to have a blind-spot. I have a requirement that the function call from Application to Service be blocking, but service needs to do ...
12
votes
9answers
651 views

Inheritance gone wrong

I have some code where a good inheritance model has gone downhill and I am trying to understand why and how to fix it. Basically, imagine you have a Zoo hierarchy with: class Animal class Parrot : ...
7
votes
2answers
305 views

Const C++ DRY Strategies

For avoiding non-trivial C++ const related duplication, are there cases where const_cast would work but a private const function returning non-const wouldn't? In Scott Meyers' Effective C++ item 3, ...
2
votes
0answers
47 views

Should the order of definitions correspond to the order of declarations in header/source files? [closed]

If my header looks like this: class foo { public: foo(); ~foo(); QString b(); QString c(); QString a(); void setB(QString s); void setC(QString s); void ...
2
votes
2answers
55 views

Reading using non-blocking IO on a fd asynchronously in C++ (moving from Node.js)

I'm trying to switch my brain from Node.js/Objective-C iOS programming to C++ programming, and it's a little bit taxing. Node.js and Objective-C with iOS do not have a run loop that I am supposed to ...
3
votes
1answer
69 views

Design approach to outsourcing a socket in an own thread

I want to extend an existing server written in C++ to be able to communicate with an other server over websockets (e.g. logging or user authorisation purposes). All examples (including the very well ...
2
votes
1answer
123 views

What design pattern best suits managing handles to objects, without passing handles or Manager around?

I'm writing a game in C++ using OpenGL. For those that don't know, with the OpenGL API you make a lot of calls to things like glGenBuffers and glCreateShader etc. These return types of GLuint which ...
0
votes
0answers
66 views

Why are datatypes different in terms of bit size based on complier, and OS used

I was reading a tutorial on C++ as I am new to programming, and I was wondering why the sizeof operator gives different output depending on what you're programming with.
4
votes
2answers
179 views

Rust-style error handling in C++

I've been reading some articles on how Rust does error handling using the Result<T, E> type and to me it seems like a hybrid best-of-both-worlds (exceptions and return codes) solution which can ...
1
vote
1answer
585 views

Interface questions for using Command Pattern and Dependency Injection together

I have many projects that have essentially the same high level requirement: test all hardware on a device. Each device can have a different communication protocol, requires different test equipment to ...
3
votes
1answer
157 views

When writing a math library, will operator overloading maintain OOP?

I want to make a fairly complicated mathematical library for a personal project and then have a visualization/GUI to go along with it to demonstrate the maths - nothing hardcore like topology but just ...
1
vote
1answer
146 views

audio file processing in C++

I thought of the following project that I want to pursue: I want to create a C++ program, that can play audiofiles and visualize the amplitudes of individual frequency bands in real time (e.g. with ...
0
votes
1answer
96 views

Modular programming practices

As I start to code more and more, for example in C++, I tend to also want to learn more about the accepted standards for code. I'm trying to code a chess engine right now, but I'm unsure how to treat ...