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

learn more… | top users | synonyms

2
votes
2answers
117 views

Are there alternatives to using an optional type in a multithreaded environment?

I'm making an MPMC queue in C++, and I would like to find out what the best interface for a try_dequeue method would be (I'm not concerned about its implementation). I'd like to provide a method which ...
1
vote
3answers
475 views

Is this a good design in C++?

Is it a good idea to replace getters and setters with a single function returning a reference? For example, instead of this, class Person { std::string name; public: std::string GetName() { ...
1
vote
2answers
161 views

2D linked list vs. multidimensional array/vector

I hope that programmers is the correct stack exchange for this, as it is quite a concept based question. I'm working on a data structure in C++ that is a represents data in 3D space. The x-y plane is ...
0
votes
2answers
63 views

Mobile App Development-Architecture/Platform: Main performance concern: device/UI responsiveness

I am currently investigating different alternatives for building a mobile instant messaging application for iOS and Android, using an XMPP server (probably ejabberd) as the back-end. Main requirements ...
1
vote
1answer
101 views

Multithreaded Pre/Post Functions

I'm programming an application for an embedded device. We are using an RTOS that supports multi threading. The device is supposed to mimic an older project that was programmed in plain C (without ...
2
votes
2answers
118 views

On concatenating adjacent string literals

C and C++ compiles adjacent string literals as a single string literal. For example this: "Some text..." "and more text" is equivalent to: "Some text...and more text" In other languages like C# ...
-3
votes
0answers
54 views

Difference between Applied Programming and Fundamental Programming? [on hold]

I have searched a lot about the difference between applied programming and fundamental programming but couldn't find a solution.
2
votes
1answer
57 views

class hierarchy with structurally different subclasses

I want to implement a protocol layer which sits on top of the TCP/IP stack. There is a limited set of PDUs that can be sent and for each PDU there is a class which represents it in a structured form. ...
-3
votes
0answers
24 views

Can't get data from getline to array [on hold]

#include <iostream> #include <dos.h> #include <fstream> #include <string> #include <vector> using namespace std; int main() { system("cls"); int y; ...
1
vote
1answer
99 views

How should a GUI application written in WinAPI be structured and organized? [on hold]

I've done an extensive amount of GUI programming in Winforms and WPF using C#, and a tiny bit in C++ using MFC. I'm building a personal project using WinAPI mainly to gain a deeper knowledge in ...
0
votes
2answers
66 views

C++ Data Server and J2ME client communication [on hold]

I am working on a robot that has some AI built in. However, the mandated robot controller does not have the power to do the work onboard. This means that I need to use a co-processor. I am writing ...
-2
votes
0answers
20 views

C++ ofstream adding random data to a file! [migrated]

Here is my code: std::ifstream file2(imageToAdd.c_str(), std::ios::in | std::ios::binary); if(file2){ file2.seekg(0,std::ios::end); length = file2.tellg(); file2.seekg(0,std::ios::beg); ...
2
votes
1answer
68 views

Best practice for unused inherited virtual functions (implementing superclass methods)

Let's assume I have a hierarchy of several classes each derived from each other using virtual functions. The base class acts as an interface and defines functions, which may not be required by all of ...
-2
votes
1answer
95 views

Uniqueness of for loop [on hold]

How does the for loop function is implemented so that it can accept ; as parameter separator rather than , which is trivial in normal functions.
0
votes
6answers
447 views

Where is the 'this' variable stored?

Let's take this simple c++ program as an example: #include <vector> class A { void fun() { a = this + 1; } A* a; }; main() { std::vector<A> vec; vec.resize(100); } Forgetting ...
3
votes
1answer
196 views

Why did GCC switch from Bison to a recursive descent parser for C++ and C?

Was there a language change that required it or some practical reason why Bison was no longer appropriate or optimal? I saw on wikipedia that they switched, referring to the GCC 3.4 and GCC 4.1 ...
2
votes
1answer
52 views

Drawing a custom rendered control in Windows - resizing

Some background: in order to learn GUI programming and drawing in Windows I'm starting to create my own GUI toolkit in Windows (so this is a didactic exercise, please don't suggest "use Qt" or "use ...
-5
votes
1answer
65 views

c++ GUI application in linux without toolkit [on hold]

We all know , there are number of toolkits available for GUI application in c++ for Linux. But for some reasons I want to create a GUI application without any toolkit.I know this question is ask ...
1
vote
1answer
269 views

Binary Tree/Knowledge Base design C++

Currently I have a binary tree template setup where my main is using it with strings to make a question/answer game. I'm using a knowledge base that works as an interface to the binary tree that main ...
4
votes
7answers
957 views

Why do we need to include the .h while everything works when including only the .cpp file?

Why do we need to include both the .h and .cpp files , while we can make it works with making just a .cpp file and then including it . For example, Creating a file.h containing declarations, then ...
-3
votes
0answers
71 views

How can I learn C++ from scratch with eBooks? [closed]

I want to learn C++. I cannot buy books. I'm looking for online resources. Articles will be a tough one. I'm looking for some professionally-written eBook (or any other document). Please suggest such ...
0
votes
1answer
124 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 ...
0
votes
1answer
140 views

Cheerp — C++ for web: advance or regression? [closed]

Recently I've run into Cheerp, a C++ to Javascript compiler, which uses a modified version of clang to generate Javascript code from C++ sources. That makes me wonder: why in the seven kingdoms would ...
3
votes
1answer
188 views

Is my class structure good enough?

So I wanted to try out this challenge on reddit which is mostly about how you structure your data the best you can. I decided to challenge my C++ skills. Here's how I planned this. First, there's ...
18
votes
14answers
3k views

University teaches DOS-style C++, how to deal with it [closed]

I had been programming for many years but wanted a diploma to make myself more employable. Having already been through university once, I didn't choose a full 5 year computer science major but a ...
5
votes
2answers
378 views

C++ Without Source Files

Bjarne Stroustrup mentions in his book "The C++ Programming Language, 4th Edition" that not all C++ implementations use files to store and compile code: There are systems that do not store, ...
23
votes
9answers
2k views

Interface design where functions need to be called in a specific sequence

The task is to configure a piece of hardware within the device, according to some input specification. This should be achieved as follows: 1) Collect the configuration information. This can happen at ...
0
votes
3answers
236 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 ...
-2
votes
1answer
148 views

What are steps in making an operating system in C ? [duplicate]

I am trying to make an my own OS. This is for educational purpose only, so that I get to understand the internals as well as get a good idea of low level programming. I have some prior application ...
16
votes
13answers
4k views

Why do operating systems do low level stuff in C and C++? Why not just C++?

On the Wikipedia page for Windows, it states the Windows is written in Assembly for the bootloader and task switcher, and C and C++ for kernel routines. IIRC, you can call C++ functions from an ...
3
votes
1answer
84 views

Augmenting functionality of subclasses without code duplication in C++

I have to add common functionality to some classes that share the same superclass, preferably without bloating the superclass. The simplified inheritance chain looks like this: Element -> ...
2
votes
4answers
201 views

How to refactor a myriad of similar classes

I'm faced with similar classes A1, A2, ..., A100. Believe it or not but yeah, there are roughly hundred classes that almost look the same. None of these classes are unit tested (of course ;-) ). Each ...
7
votes
2answers
294 views

Is NAN suitable for communicating that an invalid parameter was involved in a calculation?

I am currently working on a numerical processing system that will be deployed in a performance-critical environment. It takes inputs in the form of numerical arrays (these use the eigen library, but ...
51
votes
5answers
30k views

When do you use float and when do you use double

Frequently in my programming experience I need to make a decision whether I should use float or double for my real numbers. Sometimes I go for float, sometimes I go for double, but really this feels ...
0
votes
0answers
21 views

SmartHeap crashes in _shi_removeFromFreeList [migrated]

We have a multithreaded application in C++ which uses SmartHeap-10 on Linux. new, new[], delete and delete [] are overloaded. there is inconsistent occurrence of SIGSEGV, only in delete[]. the ...
-3
votes
0answers
36 views

7 drived classes with one common base class [migrated]

i have written the following code, //main.cpp #include<iostream> #include<string> #include"human.h" #include"computer.h" #include"referee.h" #include"RandomComputer.h" ...
1
vote
1answer
207 views

Implementation of instance testing in Java, C++, C#

For curiosity purposes as well as understanding what they entail in a program, I'm curious as to how instance testing (instanceof/is/using dynamic_cast in c++) works. I've tried to google it ...
-2
votes
2answers
89 views

Does a custom scripting language require it's own compiler/assembler? [closed]

Or is the script generally converted to a known language such as C++ first? And how generally to you integrate a scripting language with the say a game engine?
8
votes
5answers
902 views

Are there technical limitations or language features that prevent my Python script from being as fast as an equivalent C++ program?

I'm a long-time Python user. A few years ago, I started learning C++ to see what it could offer in terms of speed. During this time, I would continue to use Python as a tool for prototyping. This, it ...
13
votes
10answers
1k views

What is the best aproach for coding in a slow compilation environment

I used to coding in C# in a TDD style - write/or change a small chunk of code, re-compile in 10 seconds the whole solution, re-run the tests and again. Easy... That development methodology worked ...
1
vote
2answers
123 views

Is it an anti-pattern to use void* and enums to enable type-checking?

Say in a game engine, you have Objects that composited of different components. One of these is a RenderComponent which can be either a Mesh, a Sprite or a Light. Now, all these are vastly different ...
0
votes
1answer
202 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 ...
1
vote
1answer
101 views

In C++, are acquire-release memory order semantics transitive?

According to cppreference, we can use release-acquire semantics to ensure write-read precedence between two threads as follows: // Thread A 1. Write to X 2. Atomic store to Y with ...
6
votes
3answers
692 views

Is it bad idea to use flag variable to search MAX element in array?

Over my programming career I formed a habit to introduce a flag variable that indicates that the first comparison has occured, just like Msft does in its linq Max() extension method implementation ...
2
votes
3answers
275 views

Trying to get a better understanding of object-oriented design's performance pitfalls

I'm currently in a high-performance computing class taught in C++. Usually, I do work in C#, meaning everything is taken care of for me, and optimization comes behind maintainability and higher-level ...
-2
votes
2answers
48 views

Know executables files launched/loaded by an executable file [closed]

I would like to know any executable files launched or loaded by an executable file (if possible without running it,if it is not possible i don't want any change in the system). For example i have ...
2
votes
2answers
225 views

Code re-use in C++, via multiple inheritance or composition? Or…?

I originally asked this question on StackOverflow, but I was directed here, and I think my problem is perhaps as much conceptual as technical, so here goes. If you’re defining a hierarchy of abstract ...
0
votes
5answers
258 views

Should we only catch in exceptional circumstances?

Whether error handling by throwing exceptions is good or bad is contentious. Are exceptions as control flow considered a serious antipattern? If so, Why? The common line is that exceptions are for ...
-4
votes
1answer
99 views

Calculate Pi to N number of places [closed]

I am trying to work out how to calculate Pi to N decimal places, I think the default DP's for a float/double is 5 and then you have setprecision() however these are obviously inadequate, I need ...
12
votes
3answers
498 views

Debugging memory corruption

First off, I do realize this is not a perfect q&a style question with an absolute answer, but I can't think of any wording to make it work better. I don't think there is an absolute solution to ...