We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
2
votes
2answers
196 views

How to best unify different data formats?

I have a hardware device connected to the computer and on the hardware device there is 512 bytes of memory for storing parameters. I want to read this data and decode the parameters stored in the ...
4
votes
3answers
177 views

How to adhere to the Open Closed principle in a procedural language like C

In Robert Martin's seminal 1996 article "The Open-Closed Principle" he presents an example in C which does not follow the principle (the DrawAllShapes() method is not closed for modification): enum ...
-2
votes
0answers
51 views

Need help in Classes, Maps,Lists from C to C++ Application [on hold]

I am from C background, trying to write a C++ application. Below is the code i have come up, the purpose of application is to store a list of countries,and to create a mapper between the name of the ...
-4
votes
0answers
23 views

Libedit usage for command history implementation [on hold]

I am trying to implement command history into an existing project. I am about to make use of 'libedit' commandline editing functionality. Any help or suggestion to get started. Should I write new ...
10
votes
5answers
686 views

why aren't the platform specific integer types in C and C++ (short, int, long) deprecated?

TL;DR: Why isn't everybody screaming, "Don't use short, int, and long unless you really need to, and you very likely don't need to!" I understand that, in theory, by using the types short, int, and ...
1
vote
1answer
220 views

What are the possibilities to embed GIT into application in order to manage version control of the projects that were created by that application?

I am developing an C++ application, which creates tree like structures (collections) of strings. I want to add the ability to save the information of these tree structures remotely/locally (can be ...
2
votes
2answers
86 views

Processing user commands and parameters

I'm writing a GUI application which needs the facility for users to interact with the system and execute tasks via a sort of command line interface. The user will type commands in a text box, with ...
25
votes
7answers
6k views

Can abstractions and good code practice in embedded C++ eliminate the need for the debugger?

I am a C developer for an embedded system. YouTube has recently started recommending "C++ for embedded systems" talks. Having watched some of them, they pique my interest, but none of them answer the ...
4
votes
1answer
73 views

Coupling and shared entity classes

I am currently working on a problem that has a central controller that is handling inputs and outputs between various modules and maintaining a number of entity classes as these change. When working ...
3
votes
3answers
12k views

C++ derived class copy constructor

If I have an abstract class Drink which has a derived class Coffee, what would the copy constructor for Coffee look like? If it accepts a reference of Type Coffee as a parameter then I wouldn't be ...
0
votes
1answer
258 views

Handling Different Parameters for Derived Classes

I'm designing an API and I ended up having a few pure abstract classes. Because of the nature of the problem that I'm solving, each derived class has to be initialized with different sets of ...
3
votes
1answer
100 views

Keep track of intializations done in a function

There is an initialization function in my app that does multiple inits. What is a good way to keep a track of inits done so that if init n fails all inits done before it must be cleaned up/de-init ...
-3
votes
1answer
64 views

How to make code runnable on open source code editors like Ace Editor?

For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor. However, I feel ...
1
vote
1answer
84 views

Public class members in PIMPL

I'm attempting to use the PIMPL idiom. This is my public header file in include/foo.h: class FooPrivate; class Foo { public: Foo(); ~Foo(); private: FooPrivate* p_impl; }; ...
-2
votes
0answers
31 views

Quickest route from point A to Z through all other points

I'm a novice in graph theory and I'm looking for a relatively easy algorithm [implementation] for finding the most efficient route from point V1 to point Vk through all points V2, V3, ... , Vk-1. The ...
11
votes
8answers
12k views

Is it a bad practice to include all the enums in one file and use it in multiple classes?

I'm an aspiring game developer, I work on occasional indie games, and for a while I've been doing something which seemed like a bad practice at first, but I really want to get an answer from some ...
76
votes
3answers
73k views

Why is Python written in C and not in C++?

In Python's tutorial one can read that Python's original implementation is in C; On the other hand, the Python implementation, written in C, (...) I'm very curious why was Python written in C and ...
5
votes
1answer
288 views

Best practice for grouping related constants

I'm working on Finite Element code in MATLAB, and the number of constants (for instance user input defining the geometry, physics, numerical solution scheme) is substantial. Currently, I've been ...
2
votes
3answers
198 views

Best way to conditionally exclude unused code (C++03)

I'm working on a bare-metal embedded system, with a class that can be compiled for different hardware versions. The class takes in a pointer to a device and uses it, or takes in NULL if the device is ...
3
votes
5answers
497 views

Is there a way to speed up a big switch statement?

As a practice I'm working on a CPU simulator (runs at about 1.78MHz) and I'm using a switch statement to execute correct opcodes based on the value in the IR (instruction register) variable. This ...
1
vote
2answers
129 views

Is there a natural architecture design where I should use mutable member variable(c++)?

I have come across mutable variables kind often, yet it seems to me it's always been use to solve a problem of design(typically coping with legacy code) rather than to answer a natural, intrinsic ...
22
votes
5answers
23k 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
0answers
53 views

C++ client-server design

The context I need to design a Client-Server(-Client) network in C++ that would allow an android application to communicate to a Raspberry Pi and back I am running everything on linux environment(s) ...
0
votes
2answers
4k views

How to use namespaces to separate interface from implementation, in c++?

As far as I can tell, you can make your interface known to others by providing your .h file. Your .cpp is the implementation. Then they can see the function names, the parameter types, the return ...
3
votes
4answers
365 views

How to use Macros in Programming to make code faster, efficient and compact

Recently I was going through some of the solutions of the best competitive programmers in the world. I found out that those people use a template while writing the programs, preferably in C++. I ...
-2
votes
1answer
50 views

OOP classes hierachies for aiding static checking justified?

upfront I develop software for big data applications of which use is beyond my control (it ends up with a user), but I am not a trained software developer. So I apologize for any wrong terminology. ...
39
votes
3answers
14k views

Why is the logical NOT operator in C-style languages “!” and not “~~”?

For binary operators we have both bitwise and logical operators: & bitwise AND | bitwise OR && logical AND || logical OR NOT (a unary operator) behaves differently though. There is ~ ...
3
votes
1answer
81 views

(C++) Ideal design pattern for associating requests/responses on socket?

I'm working on my first big C++ project and while I understand the language I'm trying to learn elegant design patterns using it. I have some low-level networking over a UDP sockets API where each ...
2
votes
2answers
255 views

Why doesn't C++ support covariance in STL containers like C# or Java?

The Covariance and Contravariance feature is well supported in C# and Java collections. However C++ doesn't support them in their STL containers. Why is it so? For example the below code will ...
3
votes
2answers
172 views

How can I cleanly handle deeply nested namespaces in C++?

The first language that I truly learned was Java. In it, it is very syntactically easy to nest classes in an essentially arbitrarily complex package hierarchy, which keeps the code organized. It is ...
2
votes
1answer
235 views

Suggestions for documenting namespaces with Doxygen

Consider several C++ classes which are all defined in a particular namespace. For cleanliness, each class is located within its own file, and are each well-documented. For the purposes of completing ...
8
votes
5answers
1k views

Undefined behavior, in principle

Whether in C or C++, I think that this illegal program, whose behavior according to the C or C++ standard is undefined, is interesting: #include <stdio.h> int foo() { int a; const int ...
50
votes
11answers
10k views

Why does C++ have 'undefined behaviour' (UB) and other languages like C# or Java don't?

This Stack Overflow post lists a fairly comprehensive list of situations where the C/C++ language specification declares as to be 'undefined behaviour'. However, I want to understand why other modern ...
14
votes
5answers
4k views

Undefined behaviour in Java

I was reading this question on SO which discusses some common undefined behavior in C++, and I wondered: does Java also have undefined behaviour? If that is the case, then what are some common causes ...
1
vote
1answer
74 views

Simple question about terminal memory [closed]

I'm running a program in C++ on a Chromebook Penguin terminal. The program runs perfectly the first time, but on consecutive runs it acquires different results. I suspect that this is because the ...
4
votes
3answers
737 views

Abstract Parent and Inheritance vs. Strategy Pattern and Composition

I'm currently refactoring a class that looks (after some refactoring and very much simplified) somewhat like this: class Foo { public: Foo(bool someFlag) : m_flag(someFlag) { }; void ...
7
votes
5answers
8k views

Why would a C executable be smaller when compared to C++ executable

I'm trying to understand why the output file sizes are significantly different when using a C and a C++ compiler. I was writing a small hello world program in C and C++, I noticed that in C version, ...
-4
votes
1answer
115 views

Is it really good idea to disable warning of C or Cpp? [duplicate]

When we are working on a big project of C or CPP, we are getting some warning. Therefore, we try to remove that warning because when we see compiler warnings that they make us feel dirty. When we ...
12
votes
2answers
2k views

Const C++ DRY Strategies

For avoiding non-trivial C++ const related duplication, are there cases where const_cast would work but a private const function returning non-const wouldn't? In Scott Meyers' Effective C++ item 3, ...
2
votes
1answer
1k views

How would you design a “multithreaded” LRU cache using C++ (unordered_map and Linkedlist)?

Please note that this is about a thread-safe LRU cache (not simply a LRU cache as specified in https://leetcode.com/problems/lru-cache/description/). It isn't a duplicate of LRU cache design question ...
1
vote
1answer
71 views

Processing data in a cluster with multiple tasks

The goal is to provide a scaleable system implementing multiple data processing tasks which can be seen as a graph. Data objects will travel that graph. Most object will visit the same nodes in the ...
29
votes
10answers
16k views

Do we still have a case against the goto statement? [duplicate]

Possible Duplicate: Is it ever worthwhile using goto? In a recent article, Andrew Koenig writes: When asked why goto statements are harmful, most programmers will say something like "because ...
2
votes
1answer
154 views

Testable class/interface in embedded software written in C++

I would like to collect feedback on possible solutions for creating testable classes/interfaces. In a normal C++ development we can use references/pointers and forward declarations to achieve dynamic ...
0
votes
2answers
514 views

Interaction between model and self-modifying data in Qt MV

I have a tree structure that represents a system of devices that are connected to the PC via serial port. In a way, this structure was inspired by tree model example in Qt and I think that helps to ...
3
votes
1answer
147 views

different collision geometries in a component based game engine

I'm writing a simple game engine and after a lot of rethinking/refactoring I settled with sort of a component based architecture (not strictly ECS, but it isn't inheritance based anymore either). So ...
3
votes
3answers
394 views

C++ Recursive Descent Parser: Global Variable Dilemma

I'll come straight to the point. I'm trying to create a Recursive Descent Parser in C++ for a hobby project which involves creating my own minimalist programming language. One thing that puzzles me, ...
5
votes
8answers
2k views

Is there a point to writing in C or C++ instead of C# without knowing specifically what would make a program faster?

I wrote a small library in Python for handling the xbox 360's STFS files to be used on my web applications. I would like to rewrite it for use in the many desktop programs people are writing for 360 ...
0
votes
1answer
73 views

Common methodology for organizing C++ source/header/library/resources? [duplicate]

I'm currently working on a C++ project in Visual Studio and can't make up my mind on how I should be organizing my files. As of currently, my file directory looks similar to the following. ->...
1
vote
1answer
215 views

What is the proper way to deal with rounding error?

I am currently working on a Physics Engine in C++. The Physics Engine is for a sandbox video game. I want to build a powerful physics engine, so therefore, it needs to be very precise. I have ...
2
votes
4answers
3k views

Legitimate reasons for circular references in C++

I have project written in C++ that I am working on which has a parent-child relationship where each child has only one parent. I had previously decided after looking at this post that I would make the ...