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

learn more… | top users | synonyms

-3
votes
0answers
45 views

Material on advanced C++ features [on hold]

I'm an experienced C programmer currently working on learning C++. Since I'm mainly interested in its advanced features I was looking for the following. Is there any tutorial or similar out there that ...
2
votes
1answer
72 views

Most efficient/cleanest way to Kill a recursive thread safely

I have a number of worker threads which all perform a flood-fill task on different regions of a bitmap. They all make calls to a recursive sub-routine with different parameters(coordinates). Fyi, I am ...
2
votes
2answers
112 views

OpenGL vs OpenCV for beginner

I am a freshman college student currently learning C++ programming. I am good at math and physics, so I am looking to specialize in 2D/3D graphics with OpenGL. My question is about the differences ...
1
vote
0answers
67 views

How to Keep Track of Thread Safe Code in a mostly Thread Unsafe Legacy Rich C++ Code Base [on hold]

For large legacy C++ code bases, notions like Herb Sutter's "const means threadsafe" don't seem to help much, because there can be an overwhelming amount of code in const functions which are modifying ...
-3
votes
0answers
38 views

Input data type conflict causing infinite loop [on hold]

The code below shows a simple program, which is a small piece of code from simple math game.But in the add() function...if we cin a data type other than an int..the console displays Try again ...
-1
votes
0answers
28 views

install tesseract on visual studio 2012 [on hold]

I am trying to use Tesseract and I followed the instructions that appear in the following link http://blog.ayoungprogrammer.com/2012/11/tutorial-installing-tesseract-ocr-30202.html (with minor changes ...
6
votes
3answers
124 views

Passing parameters that need to be copied by value or const reference

I have a basic (mathematical) vector class, which in my opinion benefits from C++'s operator overloading. Vector-scalar operations are defined as self-modifying functions in the class itself, class ...
-2
votes
0answers
29 views

A library to be able to reproduce mp3 files in Raspberry Pi [on hold]

I've been having a hard time looking for a simple library to reproduce audio files (mp3 precisely) , i've tried pyglet for python, but didn't succeed, but look, the only thing i want/need is a library ...
-4
votes
0answers
41 views

How to print The sequence of numbers in structure array [on hold]

I have the task which cannot be solved. My task is create a sequences of cards. How print my sequences ? i really need help. my solution #include <iostream> #include <fstream> #include ...
-4
votes
0answers
50 views

expected primary expression before 'bool' [migrated]

My program says "error: expected primary-expression before 'bool'" on the function call repeatOrNot (bool); under the main function. Why is this? bool fiveOrNot(); void repeatOrNot (bool); int ...
-3
votes
0answers
32 views

Class evaluate and linker error [on hold]

I wrote class evaluate to compute the answer of postfix notation.Actually want to convert infix to postfix (like 2*3+5 to 23*5+).i used shunting yard alghorithm but when i compile my code i got this ...
-4
votes
0answers
40 views

How To Make A GUI In C++ [on hold]

So, I have seen many programs (Microsoft Office, Google Chrome, etc) become predominantly coded in C++. So, I planned to started learning. I've gotten to the level of GUI, and there doesn't seem to ...
-2
votes
0answers
20 views

std::memory_order_relaxed modification order consistency [on hold]

from http://en.cppreference.com : Relaxed ordering Atomic operations tagged std::memory_order_relaxed are not synchronization operations, they do not order memory. They only guarantee atomicity and ...
-2
votes
0answers
41 views

What are the Steps/Algorithm to load/Parse an XML File? [closed]

I want to write an xml parser by my own, its a project given to me, and i should complete it, i know to search for a string, load files into memory using vectors, but is theres a way i can use this to ...
2
votes
2answers
470 views

Isn't there a chicken-and-egg issue since GCC is written in C++ itself?

Since 4.8 release, the C++ compiler GCC (the G++ part of it) is written not in C anymore, but in C++ itself. I have a hypothetical question on this. I wonder how to compile the C++ code of GCC on a ...
0
votes
0answers
59 views

Design of a datamodel in a OO way

I'm looking for some advice how to design a datamodel in OO way (C++ in special). My problem: The user input in runtime is a 1D matrix A = (a0,...,an). The program creates - on the basis of A - ...
-2
votes
1answer
84 views

C++: Creating a budget program [closed]

I've just finished a basic C++ course which has covered everything from variables, structs and functions up to classes, objects and arrays. We've done a bunch of assignments in school, but I want to ...
-6
votes
0answers
65 views

Write a program that lets the user enter 10 values into an array. The program should then display the smallest values stored in the array [closed]

On line 32, the compiler says that it expects something before the "]". What am I doing wrong? :( # include <iostream> using namespace std; int smallest (int arr[], int ARRAY_SIZE); int ...
7
votes
0answers
103 views

Message Queue for RTOS for microcontrollers

I'm currently writing an RTOS for microcontrollers. The whole thing is written in C++11 - if anyone is interested, and the link to the repository is at the bottom. Currently I'm writing a class that ...
0
votes
1answer
106 views

Introducing function waypoints to protect device [closed]

Defining a magic pointer or counter inside a program / class and checking for a fixed value before executing critical commands is a way to generate a barrier against wrong execution. This check is ...
-4
votes
0answers
38 views

How to make this header and function work, for game “connectfour” [closed]

#define MAX_ROWS 6 #define MAX_COLS 7 typedef enum color { YELLOW, RED } Color; typedef enum boolean { FALSE, TRUE } Boolean; typedef struct cell { int row; int col; Color ...
0
votes
0answers
5 views

How to use the modulus when clearing an array? [migrated]

I have a method that clears the multidimensional array. Instead of two for loops, I'm using one for O(n). In doing so, I have to check if it reached the width of the array each time in each row. I'm ...
11
votes
5answers
304 views

Allow iteration of an internal vector without leaking the implementation

I have a class that represents a list of people. class AddressBook { public: AddressBook(); private: std::vector<People> people; } I want to allow clients to iterate over the vector of ...
2
votes
1answer
64 views

Enforcing manual inclusion of a specific header file (banned.h)

Banned.h is a list of ANSI C functions that Microsoft is trying to persuade programmers to deprecate. I already know how to enforce automatic inclusion of banned.h (such as the answer to Ensuring that ...
2
votes
1answer
92 views

Use cases and usage patterns of futures vs callbacks

I've become interested in futures lately, mostly due to their inclusion in standard C++ - but I see there is an active debate over futures vs. callbacks in many programming areas, such as Node.js. ...
2
votes
2answers
251 views

Early destruction of objects in c++

I am not sure if this is the right forum of this question, but I will try here since this question about the c++ language. The problem: I use one global variable in my code which is a graphics ...
1
vote
1answer
75 views

Which design pattern restricts limits class creation to certain classes

I have a fairly simple application that is divided into two classes. The first class is the Manager class and the second class is the employee class. These are simple classes and do not inherit from ...
-4
votes
0answers
18 views

Separate two inputs C++ [migrated]

I have made a quiz helper, but, as I want it for you to be able to input a new question without starting it, I made a do/while loop. The first run goes fine. When it asks you if you want to input ...
0
votes
3answers
307 views

What can C++ do that Python cannot? [closed]

I was reading this post: http://www.quora.com/What-are-the-advantages-of-Python-over-C++ And I am wondering the converse of this question: what can C++ do that Python cannot? For example, in the ...
2
votes
2answers
93 views

Preferred way of handling errors when loading an object from a file

If I want to load an object from a file, there are a number of things that can go wrong. Thus, one needs a way of handling errors when doing so. In some languages, like haskell, one can return a Maybe ...
0
votes
1answer
97 views

Intermediate results as variables or only base values?

I have a object which has a few base variables (integers as example) and one intermediate variable for further processing. The intermediate variable can be calculated from the base vars. Now the ...
-1
votes
0answers
41 views

Unexpected value using random number generator as a function in C++ [migrated]

C++ beginner here with a problem using a functions. Please help! I am trying to make a random number generator function that I can call from within int main to cout a randomly generated float between ...
2
votes
1answer
96 views

Unique_ptr to hold memory for custom VM

I work for a company that use a custom DSL and my job is to port the VM to C++. I'm trying to do this in compliance with the C++11 standard so i use auto when appropriate, the new for syntax, etc. ...
12
votes
1answer
317 views

What is the point of making a syntactic distinction between standard and user-defined types?

Although here I will refer specifically to C++ and Bjarne Stroustrup's naming conventions, in principle, I've seen that people use somewhat similar rules for other languages here and there. So, the ...
-2
votes
0answers
27 views

How do you write to a second console? (C++) [migrated]

I had the idea of using a second console in my programs for the purpose of logging programming activity. I looked around on msdn for related functions/examples and tried to put together a simple ...
3
votes
3answers
484 views

Should an object load itself?

although I'm programming in C++ for some time now, I'm always faced with design decisions (probably due to the language's flexibility). One such problem is deciding if a method should be part of the ...
-1
votes
3answers
135 views

Objects in smalltalk and c++ [closed]

I have a question based on SmallTalk and C++. In one of the programming languages books, there is a question like: "Does an object in Smalltalk require its own private stack? What about in C++?" ...
6
votes
3answers
472 views

How to prevent others from using non-thread safe variables in a multithreading environment?

I have an application written in C++ that was originally single threaded, but, due to the increasing complexity of this project, I'll need to expand it to at least two or three threads. There are ...
-2
votes
4answers
638 views

Determining the winning condition for Tic-Tac-Toe [closed]

I'm writing a tic-tac-toe game in C++ and now I found a function to check if a player has a winning board for a connect four game. The function looks like this: bool haswon(int64_t board) { ...
0
votes
0answers
100 views

Why are the raw pointer values being overwritten/falling out of scope [migrated]

I have a C++11 function making calls against a legacy C function. I thought it would be good to create worker threads(using std::thread that will then pass variables to the C function. However, it ...
3
votes
2answers
2k views

Every function is a closure?

Wikipedia says, that closure - is a function, which has an access to variables, declared outside of the function. There is even an example: function startAt(x) function incrementBy(y) ...
1
vote
4answers
711 views

try/catch open/closed principle violation

I have three or more different custom exceptions that a class can throw and I need to use try/catch in order to discover which exception was thrown. In my point of view this piece of code violates ...
-1
votes
0answers
13 views

How to stop copying into array using fscanf when its the end of the line? [migrated]

I have a file that has lines like Bob, 2,3,13,4 Jim 3,4,15,3 ... and I'm trying to copy into my numbers array only the integers in each line, so that I could do some math with them. Problem is, I ...
0
votes
0answers
44 views

Accessing a stateful managed object from native code via a static variable [migrated]

I need to create a native C++ DLL that will be an interface/wrapper over a C# class. I've never done anything like this before, but my design is basically the same as this. In other words: I have a ...
38
votes
9answers
7k views

What did people do before templates in C++? [duplicate]

I am not new to programming, but I am one that started a few years ago, and I do love templates. But in the before times, how did people deal with situations where they needed compile-time code ...
0
votes
3answers
255 views

Using PHP or C++ for in real world electronic devices

I want to use my programing skills to make my day-to-day life easier, to do this I want to be able to program in my appliances like alarm clock or microwave or refrigerator, air conditioner etc, wish ...
3
votes
3answers
319 views

Should we add constructors to structs

We often use c++ structs to define data structure as opposed to class which can be a complete module with member methods. Now deep down, we know they both are the same (loosely speaking). The fact ...
0
votes
1answer
232 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 ...
0
votes
5answers
218 views

Race conditions in JVM languages versus C/C++

I was thinking about thread synchronization issues in compiled languages like C++, versus synchronization issues in languages like Java. I'm wondering how a JVM language like Java doesn't (at least ...
7
votes
5answers
730 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, ...