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

learn more… | top users | synonyms

1
vote
1answer
150 views

Inserting C++ code into C

What I need to do before inserting C++ code into C, and how to do it? Are there any examples to show me how this can be done. I have a good knowledge of C, but never mixed those two. Thanks for the ...
1
vote
0answers
77 views

Software Design, Generic Programming, Physical Devices, and Algorithms in C++ [on hold]

I often have data that in some contexts I want to handle uniformly, but in other contexts I wish to differentiate it. For example, I could have a vector that is series of angles or a series of ...
-6
votes
0answers
29 views

Seeking a Recommendation on C++ Textbooks [on hold]

S.E advisers, I would like to learn the C++ programming language as I need that language for my upcoming research in the cryptography and theoretical computing. Sadly, this is my first time learning ...
3
votes
3answers
235 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?
-3
votes
0answers
22 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
28 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.
2
votes
1answer
142 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 ...
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 ...
-3
votes
0answers
37 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 ...
1
vote
2answers
132 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 ...
3
votes
1answer
224 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 ...
1
vote
0answers
80 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 ...
3
votes
1answer
69 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 ...
3
votes
3answers
159 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
0answers
39 views

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

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, ...
15
votes
2answers
801 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 ...
-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 ...
3
votes
1answer
148 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 ...
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
1answer
74 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 ...
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 ...
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 ...
3
votes
2answers
96 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 ...
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< ...
-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
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 ...
-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 ...
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
vote
0answers
84 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
149 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 ...
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 ...
0
votes
2answers
91 views

Usage of objects in multiple containers in C++

In cases where there is a desire for objects to be "shared" between multiple containers, I would like to know what is the best practice in C++. For example, when implementing some path algorithms ...
0
votes
0answers
29 views

Mocking delegate constructors

I am new to Unit Testing in C++. I am supposed to write a Unit test for my code and I am using Google Mock for the same. I have gone through their turtle example. But I am still confused as to how to ...
-4
votes
2answers
67 views

Accessing member of vector< pair<pair<int,int>, int> > [closed]

I have made a pair of co-ordinates and pair it with an index in another pair. How can I access members of these vector pairs...?? Is there any better option to implement it..??
-1
votes
0answers
104 views

Templates in c++ [migrated]

template<class T> template<typename T> T max(T a, T b) T max(T a, T b) { { if(a>b) ...
2
votes
1answer
119 views

C Module - Where to put prototypes and definitions that do not belong to the public interface?

Since I am mainly an Electrical Engineer, forgive me if I am somewhat off with some terminology. I am currently programming a display driver/interface module. And like so many times before, I have ...
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
186 views

Are ANSI* Escape Sequences Proper For Coloring Text in Terminal(Linux)?

I just switched back to Linux after a few years of Windows use and am wondering if ANSI Escape Sequences are okay for coloring text. I ask because the way I did it on windows isn't capable of crossing ...
0
votes
1answer
76 views

Flat files for events and alarms

So I'm working on a project that I was introduced to a year ago. One of the features of project involves alarming the users when certain events are triggered. There is also a log of these events. ...
1
vote
1answer
150 views

Best solution to switch between new and deprecated code

We have a feature that is currently implemented, let's call it implA. ImplA works but can't do many things. So we have decided to rewrite it. But we can't just replace it right away, so we will need ...
1
vote
1answer
82 views

Are There Tools for Statically Evaluating C++ Functions for Side Effects? [closed]

I'm interested in having a tool that can evaluate whether a function in C++ has side effects. I'd like to be able to mark functions as having or not having side effects, which I think would make ...
1
vote
2answers
116 views

How can I have objects interacting and communicating with each other without forcing a hierarchy?

I hope these ramblings will make my question clear — I'd totally understand if they wont, though, so let me know if that's the case, and I'll try making myself clearer. Meet BoxPong, a very ...
1
vote
4answers
132 views

const reference and const pointer. How do they work?

I read a post about how const storage works. How does const storage work? (Item 2, Scott Myers Effective C++) This says that each segment has separate section of write protected memory and const ...
2
votes
2answers
116 views

Blocking function call with asynchronous content

I am sure that this is a common design pattern, but I seem to have a blind-spot. I have a requirement that the function call from Application to Service be blocking, but service needs to do ...
14
votes
7answers
687 views

When NOT to use virtual destructors?

I believed I searched many times about virtual destructors, most mention the purpose of virtual destructors, and why you need virtual destructors. Also I think in most cases destructors need to be ...
0
votes
0answers
101 views

Member vs free function [duplicate]

I've read similiar topics and also the following great article: http://www.gotw.ca/publications/mill02.htm I'm still not quite sure how to apply it though. Basically I have a class that is an ...
26
votes
1answer
2k views

Why does C++ not have a “pure” keyword for virtual functions?

I have always wondered why we code virtual void MyFunction() = 0; and not pure virtual void MyFunction(); Is there a reference for the basis of this decision?