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

learn more… | top users | synonyms

1
vote
2answers
122 views

Idiomaticy of macros in C++

Macros are considered a good thing by one and evil by another. Is there a rule of thumb when to and when not to use macros in C++? When are macros idiomatic and when should they be avoided?
2
votes
1answer
120 views

How do I make this functional DSL written in an imperative language more efficient?

Suppose I create a simple functional Domain-specific language (DSL) using an imperative language, in this case C++. Here is a simple implementation of a DSL that can has the notion of a simple value ...
2
votes
3answers
369 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 ...
-6
votes
0answers
39 views

Question about Easing Equation [on hold]

I want to use these equations, but they are not clear. http://gizma.com/easing/ It is stated that the current time = t, the start value = b,change in value = c,d = duration. So, in a class where i ...
-3
votes
0answers
21 views

Help creating timers (Visual Studio 2013 C++) [on hold]

I am working on a project wherein I need to create a "timer". The "timer" runs in a separate program (from the main application the user is "working in"), and therefore, the user will enter the ...
-5
votes
0answers
21 views

About Files converted From OCR? [on hold]

Is there any software or process to find the OCRd files? If anyone have idea on this please reply asap.
1
vote
2answers
127 views

shared or raw pointer c++

I am developing a noSQL database and currently moving the code from C to C++. It have class Pair, which contains a raw pointer to a memory blob. class Pair { Blob* blob; ... }; Then if you add ...
1
vote
1answer
126 views

component-based power system for a game [closed]

My issue is that I've been trying to implement a power/electrical system for a while now. I'm using Unreal Engine 4 with C++ but that's not really relevant. I'm trying to implement some sort of ...
0
votes
0answers
26 views

C++ : mixing Directx9 and default windows [migrated]

I am looking for a method of placing a DXLinked window within a windowproc as a child window. This would allow for menus/Forms controls to be externally managed before input to the DX methods. So far ...
9
votes
6answers
906 views

I believe I have mixed C and C++ code when I shouldn't have; Is this a problem and how to rectify?

Background/Scenario I started writing a CLI application purely in C (my first proper C or C++ program that wasn't "Hello World" or a variation thereof). Around midway through I was working with ...
-3
votes
0answers
36 views

Sum of a number and its digits [on hold]

So I found this problem on a website and I've been trying to solve it for a few days but I must be missing on something. I work with C++. I need to find the smallest number which, together with its ...
3
votes
1answer
211 views

How do C/C++ programs get ported to different platforms? [on hold]

Java applications can run on different platforms because they always run on top of a Virtual Machine specifically developed for each platform. So, there's no native installation, you just drop the ...
9
votes
2answers
516 views

Single-responsibility and custom data types

In the past months I've asked for people here on SE and on other sites offer me some constructive criticism regarding my code. There's one thing that kept popping out almost every time and I still ...
3
votes
5answers
344 views

What are your decision critera in C++ to make something a data member or virtual method?

(Figured this was too subjective for SO, so posting here...) I have some behavior that I can implement in various ways. At least two methods are shows in the code snippet below. Presume that the ...
44
votes
5answers
10k views

Why are there no package management systems for C and C++? [closed]

There are some programming languages for which exist a package management system: CTAN for TeX CPAN for Perl Pip & Eggs for Python Maven for Java cabal for Haskell Gems for Ruby Is there any ...
0
votes
2answers
578 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
3answers
158 views

Communication between state machine and GUI

I am writing a finite state machine in C++, designed as a library. Furthermore, I have a GUI implemented as a separate project which needs to update the user interface according to state changes ...
-1
votes
1answer
1k views

GUI-Development with QT for OpenGL/C++/MAC [on hold]

I am a complete newbie considering QT. Would you say it is recommendable to use. I would like to build a GUI for my programm. I need about 10 buttons.(Maybe more) It would also be nice to have a ...
1
vote
0answers
77 views

What design pattern best suits managing handles to objects, without passing handles or Manager around?

I'm writing a game in C++ using OpenGL. For those that don't know, with the OpenGL API you make a lot of calls to things like glGenBuffers and glCreateShader etc. These return types of GLuint which ...
11
votes
2answers
3k views

Using a stream manipulator (endl) or a newline escape character (\n)?

I don't have a specific context in which I'm asking the question, but while I was reading a beginner book on C++ I noticed the use of both an endl stream manipulator and a newline escape character ...
3
votes
1answer
68 views

How should one modularly implement related objects?

I tried to make the question title as generally applicable as possible, but I'm not certain I worded it so well. It was brought about by a very specific problem I'm having, and for the remainder of ...
15
votes
4answers
10k views

In C++ why and how are virtual functions slower?

Can anyone explain in detail, how exactly the virtual table works and what pointers are associated when virtual functions are called. If they are actually slower, can you show the time that the ...
14
votes
10answers
2k 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 ...
3
votes
1answer
147 views

Providing views to an std::container

I want to maintain a buffer of 5 seconds of sensor data. The sensor data consists, among other things, of accelerometer readings in x,y,z dimensions, gyroscope readings in x,y,z dimension and ...
15
votes
2answers
783 views

Shipping test code. Why wouldn't you?

I would like to ship unit tests alongside a product. Specifically, provide an option so that anyone with a copy of our program can hit a "self-test" button or pass --self-test on the command line and ...
-1
votes
0answers
39 views

Having trouble understanding/implementing backpropagation algorithm in neural network [on hold]

I have a simple feedforward neural network with 2 input neurons (and 1 bias neuron), 4 hidden neurons (and 1 bias neuron), and one output neuron. The feedforward mechanism seems to be working fine, ...
2
votes
1answer
437 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 ...
-2
votes
0answers
7 views

C programming code error [migrated]

So the program is still incomplete, i cant go any further cause there is an error right after the first input, i tried using visual studio 2010 and 2015, both with the same problem: unhandled ...
5
votes
4answers
2k views

What do other languages offer when it comes to infrastructure technology that could indicate its advantage over C in the future?

I have been going through interview questions and I saw one which made me stop and think for a while. It starts with a quote and asks about your interpretation and whether you agree or not. "For ...
0
votes
0answers
19 views

#define as unsigned char [migrated]

I would like to know how can I tell to compiler that a #define is an unsigned char. if #define 1 byte do this: #define AACEESS_PSS 0x80 #define ACCESS_PSS ((unsigned char)0x80) but if ...
2
votes
2answers
107 views

Member and Function Injection in C++ Across Multiple Classes

I have a problem in which a variety of classes in C++ will want some functionality that is neither a "has a" nor an "is a" relationship. The problem is that there are some members with associated ...
-2
votes
4answers
613 views

FizzBuzz on Large Scale

So I was asked to create FizzBuzz at an interview... easy enough. for(int i = 1; i <100; ++i){ if((i%3) == 0) cout<<"fizz"; if((i%5) ==0) cout<<"buzz"; ... ...
2
votes
1answer
72 views

Expandable alternative to Visitor pattern for tree traversal?

I have a tree containing various subtypes of the my base node class. I now want to traverse this tree and do something with the nodes depending on their type. The most straightforward idea is to just ...
1
vote
1answer
75 views

OO Design: Algorithm changing State (Information Flow Question)

I have a class Context, which contains an instance of an abstract class State, which has multiple concrete subclasses (this is an implementation of the State Pattern). Each State subclass executes a ...
1
vote
3answers
524 views

CRM in the context of C++ programming

I was asked by an employer about CRM in the context of C++ software development. The position I was applying for was C++ Software Engineer. I told them: As far as I know, CRM is an acronym that ...
1
vote
4answers
623 views

How should I deal with nested compositions?

I came across the following question on a website for interviews: Here are 3 products: table, chair and bench. Product can be of material: wood, metal, and plastic. Design class structures for ...
3
votes
2answers
95 views

How to setup build system for unit testing + mocking?

We have a legacy code base in entirely C++. Our build system is CMake. My first stab at unit testing was as follows: Define a target (LibraryA). This library contains the code to test. Define a unit ...
6
votes
2answers
1k views

What is the difference between function() and function(void)?

I have heard that it is a good practice to write functions that do not receive anything as a parameter like this: int func(void); But I hear that the right way to express that is like this: int ...
-1
votes
0answers
82 views

reinterpret_cast< > from one structure to another [migrated]

I'm going through a win32 program and I found part of a code contained reinterpret_cast<> from one structure to another. What happens to PKT_HEADER* pPktHeader = ...
0
votes
0answers
75 views

audio file processing in C++

I thought of the following project that I want to pursue: I want to create a C++ program, that can play audiofiles and visualize the amplitudes of individual frequency bands in real time (e.g. with ...
0
votes
2answers
69 views

Multiple threads making call to precompiled library

I have been asked this question in an interview and I thought to take advice from you guys. Say I have a pre-compiled library which references to some function say "strtok". There is no source code ...
1
vote
0answers
75 views

C++ Template Equivalence of Prototypes [migrated]

The following compiles runs and executes as expected: #include <cstdlib> #include <cstring> #include <iostream> #include <type_traits> class Freaky { public: template< ...
0
votes
0answers
39 views

Why we always have to use fgetc command in C programming instead of fscanf which do the same thing but prints strange results? [migrated]

In C programming whenever I use fgetc(file) to read all the chars until the end of the file it works. But when I use the similar fscanf(file,"%c") function it doesn't works. For example: File ...
0
votes
1answer
544 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 ...
-2
votes
0answers
19 views

Instance Variables Not Updating [migrated]

When I run my little game, battle commences but after every turn, the players attack but health doesn't go down (i.e. the game never ends and it keeps printing the same health over and over). I know ...
0
votes
1answer
73 views

Const and non-const methods, and possible mutable data member?

I'm working on a design and implementation change due to a bug. The bug fix requires us to modify a class object in a const method. I think the two options are: Have the non-const method cast this ...
1
vote
0answers
83 views

Best software architecture for an efficient network tunneling in C++

Before jumping to my questions, let me explain my project's background. I am part of a team that organize the network of a famous LAN event. Most of the games nowadays actually don't run locally but ...
1
vote
1answer
146 views

address and pointer of a char and int

I have been messing around pointers and addresses to understand them better, and in one compilation i got a result which i can not explain, please see below #include "stdafx.h" #include ...
2
votes
5answers
392 views

std::vector Non-Array Implementation?

I've seen some posts on the StackExchange family of sites talking about std::vector implementations. They all seem to indicate that std::vector is implemented strictly as an array (in practice), and ...
0
votes
1answer
105 views

pthread versus boost::thread - need to set the thread priority on an ubuntu box

I wrote a class that basically executes a numerical analysis code in a thread using boost::thread. Now I need to specify the thread priority, since we are running a system with near real-time ...