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

learn more… | top users | synonyms

6
votes
8answers
474 views

How to design an interface, where things 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 ...
-1
votes
0answers
17 views

Can emsripten compile down to Canvas-based Js instead of WebGL?

I understand that emscripten compiles down LLVM to JS and it converts OpenGL Calls to WebGL. Thats a fairly simple translation. Is there a way to tell emscripten to use some other graphics Library ( ...
-2
votes
1answer
83 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
70 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 -> ...
-1
votes
0answers
60 views

Can anyone explain segmented sieve of eratosthenes [on hold]

I've searched all over the web on implementation of segmented sieve of eratosthenes. But I found none of them suitable for a beginner. Can anyone explain me the underlying principle behind this ...
-1
votes
1answer
59 views

Cross-platform & 3D mobile game development [on hold]

I am not a developer or programmer and, I am planning an educative project that will involve having students to develop a cross-platform, 3D mobile game, similar to the SimCity concept. I need to ...
5
votes
2answers
272 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
275 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
188 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
201 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
86 views

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

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
113 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
91 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 ...
0
votes
0answers
31 views

General strategies and specific suggestions for C/C++ representations of RDBMS-like data relationships [on hold]

I hope that this question is appropriate here and apologize if it is not. I have a dataset which consists of complex token series. An example of a single sequence might be, a1|a3:ba|z4|x, a1:ba, ...
-2
votes
2answers
47 views

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

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 ...
-5
votes
0answers
54 views

Help needed regarding strings in C++ [closed]

I need to take input of two numbers from the user which are separated by a space in a single line. For eg, if the user types in 10 20 I need to store the values 10 and 20 in separate variables. Is ...
0
votes
5answers
251 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
98 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
117 views

How to be a useful c++ programmer [closed]

I am a high school student and because it is summer time I am currently learning to program(it has been 4-5 month) in several languages like c++, php, JS and if you call them programming languages ...
-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
78 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
0answers
27 views

number of grandchildren in two dimensional array of string [closed]

Given a two dimensional array of string like <”luke”, “shaw”> <”wayne”, “rooney”> <”rooney”, “ronaldo”> <”shaw”, “rooney”> Where the first string is child, second string is Father. ...
-5
votes
2answers
169 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
132 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
176 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
97 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
472 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
151 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
110 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
211 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 ...
2
votes
1answer
90 views

How modularized should my interfaces be?

I stumbled upon a specific instance where it seems that modularity and simplicity are at conflict with each other. Usually that's not the case, so I was really unsure how to resolve it. Suppose I ...
-2
votes
0answers
56 views

Dijsktra's Algorithm Implementation : Mice and Maze [migrated]

This is a simple problem involving Dijkstra's Algorithm to find shortest distance tree rooted at a given vertex. Following is the code that got accepted: #include<iostream> ...
-1
votes
0answers
30 views

how to print a char array using a pointer only? (we don't know the size of the array) [migrated]

I have a function with three parameters: a pointer to a character array (also known as a C-String), and two pointers to specific characters (we will assume that they point to characters in the ...
20
votes
3answers
3k views

Why Increment Pointers?

I just recently started learning C++, and as most people (according to what I have been reading) I'm struggling with pointers. Not in the traditional sense, I understand what they are, and why they ...
3
votes
1answer
72 views

How to define the motion path of one object on a surface of the other one?

I have an uncommon problem. There are 2 3D objects, which are represented by arrays of vertices and triangles (.stl files). Each of them contains a big enough amount of vertices: 1-10 mln ones. The ...
4
votes
1answer
227 views

Is there a reason to define type aliases in any program

I have started to learn c++ for some time ago. It is a big subject and I am not very use to it yet. Thus is this question asked more of curiosity, than something else. In the book that I read to now ...
8
votes
5answers
887 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 ...
0
votes
5answers
347 views

IS C++ a cross-platform language? [closed]

If I create a game in C++ on a mac using a library which is the same for both windows and osx, will the game be playable on both windows and os x or it will only work in os x because I done it in ...
2
votes
1answer
124 views

Is there a way to use RAII techniques in COM?

I am caught between two conceptual models of how to construct objects, and am having trouble working out what standard I want to adopt. I prefer to program in .NET and often try to use RAII and ...
-2
votes
2answers
211 views

Which algorithm is faster? [closed]

I'm creating a small game, where the computer generate pseudo random number in give range, and the user have to guess it. I also made the option to play computer vs computer. I mean the computer ...
0
votes
1answer
60 views

Is it a bad idea to use mutable for pre-allocated temporaries?

Let us assume I have the following C++ class: class MyFastMessageEncoder { public: MyFastMessageEncoder() : m_fieldEncoder(ENCODING_STYLE_DEFAULT) { } void ...
0
votes
0answers
16 views

LL1 Parsing Table, Output Table is not properly showing + buffer problem [migrated]

I tried my best what I can do to show this output table, but having hard time showing it. the code runs fine but when I try to enter the following output of table for validation, a lot of errors ...
-2
votes
2answers
278 views

How comes the C++ standards committee introduces a keyword like nullptr and gets away with it? [closed]

That must have broken a lot of peoples code bases right? Everyone who had a variable named "nullptr" (which I think would have been fairly common) has to find "nullptr" and replace with ...
0
votes
0answers
11 views

How can I pass floating point numbers as template parameters? [migrated]

I am working on a meta-programming project, and we would like to have the ability to pass floating-point numbers as template arguments. I wasn't sure whether this question would be better suited to ...
2
votes
2answers
121 views

Potentially justifiable use case for const_cast or bad design?

I'm designing a data structure in C++, and I want to expose an interface to the user to traverse the structure in some order. Instead of creating several different types of enumerators, I want to keep ...