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

learn more… | top users | synonyms

1
vote
0answers
101 views

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

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 ...
3
votes
1answer
597 views

Does it make sense to choose UTF-32, based on concern that some basic rule will be broken for UTF-8?

I'm working on an cross platform C++ project, which doesn't consider unicode, and need change to support unicode. There is following two choices, and I need to decide which one to choose. Using ...
5
votes
3answers
333 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?
1
vote
2answers
153 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
136 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 ...
9
votes
6answers
946 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
1answer
339 views

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

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
530 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
354 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 ...
47
votes
5answers
11k 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 ...
3
votes
3answers
212 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 ...
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
78 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
11k 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
154 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
882 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
1answer
442 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 ...
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 ...
2
votes
2answers
126 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
629 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
110 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
87 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
540 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
632 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 ...
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 ...
0
votes
2answers
86 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 ...
0
votes
1answer
93 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
109 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 ...
2
votes
5answers
412 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
192 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 ...
20
votes
9answers
5k views

Why there is no power operator in Java / C++?

While there is such operator - ** in Python, I was wondering why Java and C++ don't have one too. It is easy to make one for classes you define in C++ with operator overloading (and I believe such ...
0
votes
2answers
104 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
35 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 ...
61
votes
15answers
14k views

Why would it ever be possible for Java to be faster than C++?

Sometimes Java outperforms C++ in benchmarks. Of course, sometimes C++ outperforms. See the following links: http://keithlea.com/javabench/ ...
1
vote
1answer
517 views

Help me construct a list of best approaches for new C and C++ developers [closed]

Not specific code writing practices. Please also include reasoning. My start: use GCC or Clang gcc because it is unchallenged in the amount of static checking it can do (both against standards ...
2
votes
1answer
143 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 ...
5
votes
6answers
6k views

What should I know about C++? [closed]

I've recently started learning C++, and I enjoy it a lot. I've often read it's easier to write bad code in C++ than in most languages, and that it is a lot deeper than what it seems. As I'd like to ...
4
votes
5answers
3k views

Template Functions and Function templates in C++

I came across a question which asked the difference between Function Templates and Template Functions in C++ and also Template Classes and Class Templates. I was under the impression that Function ...
0
votes
1answer
205 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 ...
9
votes
4answers
518 views

Is Non-Deterministic Resource-Management a Leaky Abstraction?

From what I can see, there are two pervasive forms of resource-management: deterministic destruction and explicit. Examples of the former would be C++ destructors and smart pointers or Perl's DESTROY ...
1
vote
3answers
3k views

Is there still any value in learning assembly languages today? [closed]

Specifically for a game programmer. If you really needed some assembly routines you could look for help, whereas back in the 80s/90s it was one of the mainstream languages. I read that compilers can ...
61
votes
11answers
9k views

Why is base-for-all-objects discouraged in C++

Stroustrup says "Don’t immediately invent a unique base for all of your classes (an Object class). Typically, you can do better without it for many/most classes." (The C++ Programming Language Fourth ...
7
votes
4answers
1k views

Avoid having an initialization method

I have this existing code where they have a class and an initialization method in that class. It is expected that once the object of the class is created, they need to call initialize on it. Reason ...
1
vote
1answer
154 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
96 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 ...
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 ...
1
vote
2answers
136 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 ...
18
votes
5answers
3k views

Why do all <algorithm> functions take only ranges, not containers?

There are many useful functions in <algorithm>, but all of them operate on "sequences" - pairs of iterators. E.g., if I have a container and like to run std::accumulate on it, I need to write: ...
15
votes
7answers
2k 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 ...