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

learn more… | top users | synonyms

-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.
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 ...
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 ...
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# ...
1
vote
3answers
477 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() { ...
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; ...
-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); ...
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 ...
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
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 ...
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 ...
1
vote
2answers
162 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 ...
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 ...
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
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 ...
-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 ...
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 ...
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 ...
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 ...
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 ...
-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 ...
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 -> ...
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, ...
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 ...
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 ...
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?
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 ...
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 ...
-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 ...
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 ...
-2
votes
0answers
20 views

Get the follwoing errors when I compile with G++ [migrated]

I am a bit new to programming s you can probably tell from my prior question(s). I was wondering if anyone could help me with this recent problem I've had. I am trying to compile a script main.cpp ...
-4
votes
1answer
80 views

Unable to understand linked list example [closed]

Could someone please explain this code to me.. #include <iostream> using namespace std; struct link { int data; link* next; }; class linklist { private: link* first; ...
-5
votes
2answers
182 views

How does std::string in c++ allocate memory? [closed]

I've noticed that the string library doesn't require one to allocate space before writing the input/output. How does the string library allocate that memory dynamically, i know of the 'new' keyword in ...
-2
votes
3answers
134 views

Distributed game development and security of source code

I think this question has already been asked many times, but I can't find any of them. I have a game project (I'm using Marmalade),and a few trusted developers, but I want to invite more. For adding ...
0
votes
0answers
19 views

QMap to and from a textual representation - QTextStream? [migrated]

I am working on some code (part of KDE's kwallet) that stores a QMap as a binary representation, using QByteArray mapData; QDataStream ds(&mapData, QIODevice::WriteOnly); ds << map; ...
0
votes
0answers
10 views

how to declare a const pointer that can be used as “this” [migrated]

I have a parent XWin class to encapsulate a program's "X-calls". Once I've opened the display. I pass a pointer to the Xwin class that holds all X-related pointers (resources, display, etc) and all ...
2
votes
3answers
182 views

C/C++: Which conversion warnings make sense in practice?

C/C++ implicit conversions can cause bugs. Here's one example: int foo, bar; scanf("%d", &foo); scanf("%d", &bar); float foobar = foo / bar; If I input 7 and 2, it's not 3.5 as expected - ...
1
vote
1answer
99 views

Pulling results from postgresql with cursors

I'm writing an application in C++ using libpq as the interface to postgresql. I'm currently putting together a small library of helper functions to help deal with the conversion from C++ to C for an ...
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 ...
0
votes
1answer
152 views

Is this a specific pattern and what is its purpose? [closed]

I recently stumbled over the following C++ Code which confused me a bit: class One {/*definition*/}; template<class Base > class Two : public Base {/*definition*/}; template<class Base > ...
0
votes
0answers
58 views

Controlling frame rate [migrated]

I'm creating a bunch of threads that need to do work in a frame cycle. I would like to control how many frames are done in a second. I simplified the code I have into this so I can show you what I ...
-1
votes
2answers
116 views

Reading assembly useful for insights when writing C/C++? [closed]

While in most cases its not necessarily, recently I have taken to reading the generated assembly of my C code every so often, when I'm curious as to the kinds of optimizations my compiler is making. ...
5
votes
2answers
217 views

Processor architectures for testing C/C++ portability

Currently I'm working on a C/C++ code-base which is fairly portable, it can compile on most Unix like systems as well as MS-Windows (MSVC), using various popular compilers. Previously I've found ...