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

learn more… | top users | synonyms

2
votes
2answers
197 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 ...
2
votes
5answers
391 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. ...
-2
votes
0answers
40 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 ...
0
votes
1answer
182 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; ...
13
votes
6answers
4k views

The rule of 5 - to use it or not?

The rule of 3 (the rule of 5 in the new c++ standard) states : If you need to explicitly declare either the destructor, copy constructor or copy assignment operator yourself, you probably need to ...
-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 ...
3
votes
3answers
289 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? ...
0
votes
1answer
246 views

GUI code implementation for specific Window/Form class

Terminology Element/Form Element -> Fields such as text list, combo_boxes, push buttons, etc. Problem I have a program that is basically a fat client that interfaces into a system that keeps track ...
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. ...
8
votes
5answers
184 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 ...
1
vote
4answers
274 views

Application qos involving priority and bandwidth

Our manager wants us to do applicaiton qos which is quite different from the well-known system qos. We have many services of three types, they have priorites, the manager wants to suspend low priority ...
3
votes
2answers
158 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
62 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 ...
1
vote
0answers
148 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 ...
2
votes
1answer
136 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 ...
-3
votes
0answers
67 views

Material on advanced C++ features [closed]

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
2answers
158 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 ...
5
votes
2answers
1k views

Performance and other issues with using floating point types in C++

Being interested in C++ performance programming there is one aspect I really have no clue about- and that is the implications of using floating point calculations vs doubles vs normal integer ...
6
votes
3answers
137 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 ...
0
votes
1answer
363 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 ...
-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 ...
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 ...
3
votes
2answers
504 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 - ...
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
1answer
276 views

Creating a custom GUI. App/DE/WM?

I am starting with this project of mine of writing a custom UI for linux. What would happen is: The computer would boot into this UI which would not be the typical taskbar/icons/startbutton kind of ...
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 ...
5
votes
2answers
8k views

How to run C++ code in browser using asm.js?

An asm.js application is very fast (near native C++ speed): http://kripken.github.io/mloc_emscripten_talk/micro4b.png But how is it possible to write one in C++, convert it to LLVM code, then do ...
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 ...
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 ...
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
77 views

saving connectivity information in a nodes/edges network

I want to implement the A* algorithm. I have a network with Nodes and Edges, both are classes. Now, I am unsure how to approach the connectivity information. Should a node know which edges depart ...
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. ...
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
328 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 ...
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 ...
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 ...
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
vote
3answers
262 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 ...
10
votes
6answers
17k views

Why are constructors not inherited?

I am confused as to what the problems could be if a constructor was inherited from a base class. Cpp Primer Plus says, Constructors are different from other class methods in that they create ...
55
votes
17answers
6k views

What programming problems are best solved by using pointers?

Well, I basically understand how to use pointers, but not how best to use them in order to do better programming. What are good projects or problems to resolve involving the use of pointers so I can ...
15
votes
6answers
1k views

Is it a good habit to use C expressions in C++ code?

At school we started learning C this year, despite the fact I'm way ahead of class, and I learned Java, C++ and C while the class is at the base of C. Anyhow, I've been documenting myself, reading ...
-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. ...
17
votes
3answers
3k views

How to solve the problem of nested comments

It appears in not just one language that comments can't be nested. Do you have a good solution for this problem? One workaround in C/C++ and Java is to only use the single-line comment but it becomes ...
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 ...