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

learn more… | top users | synonyms

0
votes
0answers
16 views

How to compare numbers in a file?

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, only write the ones that are not duplicated, while letting the user ...
2
votes
1answer
89 views

What would be a reason not to embed JS in C?

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 ...
-4
votes
0answers
52 views

Where can I find a compiler [on hold]

and tried looking for a c compiler. I have tried GCC which is now GNU I think now, but did not seem to work is there any advise people can give to some just looking to start out thanks Hayden
0
votes
0answers
20 views

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

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 ...
0
votes
0answers
40 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 [on hold]

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
609 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
25 views

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

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
129 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 [on hold]

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? [on hold]

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
183 views

How often should RAII be used? [on hold]

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 [on hold]

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
91 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
192 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
137 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 ...
-2
votes
0answers
47 views

Visual Studio 2015 C++ mobile cross platform documentation? [closed]

Apparently VS 2015 comes with tools that allow for the development of iOS / android / WP apps in pure C++ with native performance. I can't seem to find a single page of documentation other than the ...
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, ...
0
votes
0answers
49 views

Needing pointers on writing my first C++ library [closed]

I'm a CS undergrad attempting to write my first C++ library as a practical exercise, so I'm writing a rendering engine that uses the SFML library (link for the unfamiliar). Unfortunately, there's a ...
1
vote
0answers
49 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 ...
-3
votes
0answers
32 views

Looking for a package to visually show this [closed]

I want to be able to visualize a very long string of say 1000 characters in one line. From there the user can horizontally scroll through that long string of 1000 characters or zoom in to only see the ...
5
votes
2answers
754 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
123 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
152 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
646 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
299 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 ...
0
votes
1answer
192 views

C code to object oriented [closed]

My research mentor provided me with some C++ code. Trouble is, it's basically C: it's in one big file, the header doesn't declare a class or even prototype functions, the filename and content of an ...
2
votes
2answers
53 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
63 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
122 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
176 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
581 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
143 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
92 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 ...
0
votes
0answers
56 views

c++ constructor and operator problem [migrated]

I have a problem with constructor and assignment operator. This is my code: class Class { private: double number1; double number2; public: Class(double, double); ...
4
votes
0answers
47 views

Directory organization of a CMake (C++) repository containing several projects

I would like some advises on the organization of a set of related but independent C++ projects stored in a single (git) repository. The projects use CMake. For a simplified example we imagine 2 ...
3
votes
2answers
109 views

C++ using shared_ptr with API [closed]

I'm building a library that generates a couple of types of objects that can be used by user code and the library. To keep track of these objects, I'd like to use shared_ptr's, so I can build in some ...
2
votes
1answer
136 views

Does applying a prefix to member variables make sense in C? [closed]

//C code struct Foo{ int m_nVar; } struct Foo f; f.m_nVar = 0; Despite the fact that many consider Hungarian Notation an anti-pattern, I am working in a code base that enforces it. 90% ...
4
votes
3answers
178 views

Strategy for fixing signed/unsigned warnings

I'm working on obtaining a clean compile with -Wsign-conversion for existing library code. The library is 25 years old or so. Eventually, this higher bar will be a security gate, and all check-ins ...
2
votes
1answer
49 views

How does condition_variable::notify_one() choose which thread to unblock?

notify_one() of C++ 11 thread library is used to unblock one of the waiting threads. How does it choose which thread to unblock? To begin with, I tried googling but could not find any appropriate ...
-3
votes
0answers
39 views

How to get/set value for pixels C++ SDL [migrated]

I'm making a basic 2D rendering engine in C++ with the help of SDL but I can't find the answer to one question: how do you get/set values for pixels without having to access each individual pixel? ...
0
votes
2answers
138 views

bool accepts int literals, char literals, string literals - why?

Programming: Practices and Principles - Bjarne Stroustrup Drill in Ch 5 - Errors He wants us to correct the code: boo c = "fool"<s; On correcting boo to bool, this is a comparison, so that's ...
3
votes
2answers
104 views

In C++, when should I use final in virtual method declaration?

I know that final keyword is used to prevent virtual method from being overriden by derived classes. However, I can't find any useful example when I should really use final keyword with virtual ...