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

learn more… | top users | synonyms

0
votes
2answers
21 views

How do you decide member objects?

So OOP is about breaking down functionality, making each class responsible for one thing etc. But let's take the example where an object is using another object. First thing that comes to mind ...
-5
votes
0answers
34 views

Isn't this question misplaced in 'easy' category? [on hold]

I just want to know whether is it just me or also some of the users here believe that this question is really not 'easy'. I spent 15-20 minutes on it but still I'm not able to deduce an algorithm for ...
-2
votes
0answers
41 views

String of zeros vs correct output [on hold]

int characterSum = 0; string numberString = to_string(number); int size = numberString.size(); double *decimalDigit = new double[size]; while (0 <= size - 1){ //acquire digits of number ...
4
votes
2answers
205 views

Is the rule of 5 a valid extension of the rule of 3, or does it imply premature optimization?

I'm familiar with the notion in c++ of the rule of 3, however since the release of C++11 I've seen some sources suggesting it should be extended to a "rule of 5", I.e. the move constructor and move ...
-1
votes
1answer
84 views

Passing by argument vs keeping it as a member

I really cannot decide what option is the best, I see plenty of down/upsides to both approaches and right now I'm undecided. For example; class DX11GBuffer { public: DX11GBuffer(ID3D11DevicePtr ...
0
votes
1answer
191 views

The difference between *s.pd and s->pd

I was reading about copy constructors for structs and i found this example: #include <iostream> #include <string> using namespace std; struct SomeData { int * pd; string id; ...
2
votes
5answers
403 views

Why lambda/closures expressions came so late to C++?

I was reading a really great Bjarne Stroustrup's article where he exposes some C++ myths. I look at code that focus my attention, because I wouldn't know that C++ supports this kind of expressions. ...
10
votes
3answers
2k views

Non-Object Oriented Programming in Object Oriented Language [on hold]

Recently I was assigned a task of creating a calculator with functions addition, subtraction, multiplication, division and power using Object Oriented Programming. I successfully completed this task. ...
3
votes
3answers
292 views

How to use multiple programming languages together in the same program? [on hold]

Such a simple question, but I have not found a reasonable answer to this. I currently program in Python, an interpreted language. I always hear of people using multiple languages in the same program? ...
9
votes
5answers
197 views

Correctly disposing objects upon server termination

I am working on a large C++ project. It consists in a server that exposes a REST API, providing a simple and user-friendly interface for a very broad system comprising many other servers. The codebase ...
3
votes
2answers
160 views

Why define struct in variable?

Consider the following program: Many people when they want to use a struct, they create a new variable as: struct structureName variableName While it works when you just define it as: ...
-4
votes
0answers
17 views

How do I create the windows explorer kind of search bar with QT [closed]

I am currently writing a program with QT using sqlite database and I need to write code to query the database and I want it to be like the search bar in Windows. such that as the user types, it brings ...
-5
votes
0answers
63 views

C application vs C++ application [closed]

What are a real life application that is based on C language rather than C++? Why is it using C and not C++ since they are almost the same? Do you think we can convert that application to C++? And how ...
-5
votes
0answers
35 views

Getting the Max Age of a student using Class C++ [closed]

Please, help me and check my program:i want to use the maxAge() member function to get the student age (Maximum age) entered from the function MAIN using the while loops which i stored into the ...
2
votes
1answer
137 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
160 views

OpenGL vs OpenCV for beginner [on hold]

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

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

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 ...
6
votes
3answers
138 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 ...
-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
2answers
515 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
65 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 - ...
7
votes
0answers
124 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 ...
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
314 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
71 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
97 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
255 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
76 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
329 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
97 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
100 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
321 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 ...
3
votes
3answers
487 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
136 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++?" ...
7
votes
3answers
479 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
659 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) { ...
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
714 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 ...
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
268 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
324 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
233 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
220 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
731 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, ...
3
votes
2answers
238 views

What's wrong with statically linking the STL into multiple shared libraries?

Here is the scenario: libA.so and libB.so both statically link to the same STL. libA.so has a public API that returns a std::string. libB.so calls this function and receives a copy of the string. ...
1
vote
3answers
234 views

Including extra headers that I do not really need

I always wondered what are the effects of including not needed headers to the final executable once compiled. In my code some times I may included many different headers that I do not need (or I used ...