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
2 answers
401 views

good design for signal handling in main executable

I have a executable that starts up some resources, spins a bunch of worker threads and then waits in a loop for the done command. After the done command is received, it does a bunch of clean up and ...
user avatar
1 vote
1 answer
155 views

Best way to structure multiple constants C++

Context I'm developing a chess engine of my own, where if anything can be pre-initialized/pre-calculated, should be. This is because speed is the number-1 priority, and every extra second you spend ...
user avatar
1 vote
1 answer
101 views

Is this a good use of template specialization? Or should the factory method be used?

I have a program that involves two different data structures, and so I created a class that acts as a generalized data structure that either of the original two can be represented as. (Because the ...
user avatar
  • 19
1 vote
4 answers
414 views

Using output arguments in C++ to avoid dynamic allocations

I have a function that repeatedly encodes Foos to string. I'm currently deciding between two ways to implement this: Return by value: std::string encode(const Foo& foo); void important_function() ...
user avatar
  • 157
1 vote
2 answers
325 views

Is there a difference between abstract data type and interface?

From what I understand, an abstract data type is basically some data and what we are allowed to do with that data (ex. a list with a set of data and an attribute size and the functions get(), set(), ...
user avatar
  • 163
26 votes
6 answers
8k views

What does it mean when you say C++ offers more control compared to languages like Python?

I am comparing C++ with Python. It is clear that C++ is much more efficient and that the C++ code compiles directly to machine code whereas in Python it is interpreted. I do understand that Python is ...
user avatar
2 votes
1 answer
112 views

Ask for suggestion: data type for parsing stringified fractional numbers

I am the author of a C library for parsing INI files. So far I have delegated the task of parsing values as numbers to the standard atoi() family of functions. However I think time has come that I ...
user avatar
  • 129
3 votes
3 answers
483 views

Why am I getting complex errors even with simple C++ code?

I started to play with C++ recently. One of the difficulties I have quite often is when the compiler tells that there is an issue with the types: more often than not, those compiler errors look ...
user avatar
1 vote
3 answers
121 views

What's a good way to inplement a "delete" function for my custom polymorphic widgets?

I'm currently trying to make a simple program with UI where a user can add, select and remove different objects inherited from an abstract common interface with a mouse. What I plan to do is use a set&...
user avatar
-2 votes
3 answers
416 views

How to avoid giant main function because of dependency injection

I try to use dependency injection as often as I can but every time I end up with the same problem : I always have a giant main function. If I use it without any framework and send the classes in the ...
user avatar
  • 934
1 vote
2 answers
353 views

How to avoid cascading dynamic casts?

So, in general casting and dynamic_cast in particular are to be avoided. But I don't see a proper alternative for this: List<DerivedA*> ListA; List<DerivedB*> ListB; Bool Add(Base* obj) { ...
user avatar
  • 21
0 votes
2 answers
316 views

Implementing C++ n-ary tree with Boost Graph Library

I would like to have a relatively small and simple tree in C++. Each node would contain an integer. The tree should be traversable both ways. I know it can be done with tree.hh by Kasper Peeters, but ...
user avatar
  • 1
1 vote
1 answer
170 views

What's an efficient way to serve hundreds of gigabytes of text records to search clients in C++?

I am building a three-tier architecture application that receives compressed (zlib) text records from a data store, decompresses the records into structs, and then serves the records to clients over ...
user avatar
3 votes
1 answer
239 views

Are there any C++ command pattern implementations which make it easy to add additional functions and their parameters

For my situation I have a device receiving string commands such as turn_on, pump, etc. Some of these commands also have arguments attached to them such as an int. I have methods like this void turn_on(...
user avatar
1 vote
2 answers
436 views

C++ Organizing classes for easy unit testing (but with some restrictions)

Mild pickle. I have a project which has components that are difficult to test/mock. It might look something like this: class Contenxt; class Server : public SomeOtherClass { public: ServerPlugin(...
user avatar
2 votes
2 answers
163 views

Is switching sub-class at runtime a proper use case for inheritance?

I've got a DataSource base class and a few different sub-classes. I want to be able to switch which sub-class i'm using at runtime so I'm doing the following : // pointer for our datasource object ...
user avatar
  • 139
5 votes
1 answer
237 views

Create C++14 library where each class has 2 similar variants

I'm writing a C++ library which does some computation on vectors of audio data. The library supports both GPU (using Thrust, a C++ STL-like library for GPUs) and CPUs (using the STL). I'm using CUDA ...
user avatar
  • 89
1 vote
3 answers
369 views

Efficient way to encode moves and container choice for chess moves for an engine

I am working on my chess engine in C++ and I went for bitboards to represent the board. It is basically a 64-bit number for which I use the bitset library. I feel the most crucial part in performance ...
user avatar
2 votes
1 answer
541 views

How to store a vector of smart pointers, except some of them are owned by another object?

I'm making a basic platformer game. I have a Game class as well as Level class. The game object holds a pointer to the current Level object. A level currently has a std::vector of GameObject raw ...
user avatar
0 votes
2 answers
917 views

Why are some languages called platform dependent if I can always share the source code?

I was reading about erlang when I read that it is platform-independent, using BEAM as the VM, now I understand that a VM compiles the byte code to machine code and this makes that language machine-...
user avatar
  • 129
-3 votes
1 answer
181 views

Data structures or coding styles in C++ for avoiding long elseif chain when parsing?

Lately I have created some small parsers of data. My initial code structure // more cases here ... else if(!strcmp(X,"somekey")){ // Parse according to "somekey" behavior. } // ...
user avatar
1 vote
0 answers
75 views

What is a good design for accumulating temporary data stemming from several processing runs?

I would like to compute cycle times for some manipulator movements. These movements consist of different phases. I have a class that models these phases and this is its constructor to give an idea: /**...
user avatar
-2 votes
1 answer
156 views

What is the point of inheritance in c++ programming? [duplicate]

Classes in c++ can be extended, creating new classes which retain characteristics of the base class. This means we can create something like this : struct Person { struct Person** children; ...
user avatar
  • 119
1 vote
3 answers
195 views

Is it a good practice for functors to store outputs as instance attributes?

The question pretty much says all, but let's look into a simple example (I'm using C++, but the question is not strictly related to any particular language): So, let's say that we have a functor that ...
user avatar
  • 137
1 vote
2 answers
148 views

Going from Javascript to C++. I have teacher and student objects, and I want to display if they are teachers or students. How should I do this?

This may be too general of a question, but basically whenever I try to find an answer for something that would work from a Javascript approach, the answer heavily implies that you wouldn't do it that ...
user avatar
2 votes
1 answer
2k views

how to represent functions and global variables in UML?

I'm going to translate into UML a C++ project I have been doing for a few days and which I estimate convenient to handle as a model for a way better management. The problem is the following: I tried ...
user avatar
0 votes
1 answer
120 views

How to maintain SRP with a chain of async functions?

For code maintainability I understand that it is generally better to have code structured like this: void abc() { a(); b(); c(); d(); } Instead of like: void abcd() { a(); bcd(...
user avatar
0 votes
1 answer
297 views

Capture by value/reference and early/late binding

Is capture by value (x below) an early binding and capture by reference (y below) a late binding in C++ lambdas, or are they both early bindings—the first by value and the second by reference? #...
user avatar
  • 570
5 votes
1 answer
207 views

Real-world scenarios for protected inheritance

C++ supports protected inheritance: A class can derive from a base class B in a way that the "outside" world doesn't see that class "as a B" but the class itself and it's derived ...
user avatar
6 votes
6 answers
681 views

How is design using C different from C++?

A employer is looking for C programmers, and I'm told they say that ... Good C design isn't the same as good C++ design ... and so they're looking for candidates experienced with C and not only C++. ...
user avatar
  • 3,357
0 votes
1 answer
109 views

Which scope should markers for a Stack Allocator fall under?

For reference, I am reading from "Game Engine Architecture 2nd Edition" by Jason Gregory. Although I understand the theory behind Stack Allocators, I am having trouble implementing it fully. ...
user avatar
1 vote
1 answer
721 views

Is having side-effects in constructor an anti-pattern?

I was trying to understand how to embed v8 engine in a C++ application and was trying to understand the following hello world problem as a result. I found the code to be unreadable at first glance. e....
user avatar
1 vote
1 answer
186 views

How can I do memory management in C++ when a class needs to throw out and replace a member object many times during its lifetime?

I'm writing a C++ application. This is a memory management question, I have a background in scripting languages and am new to C++. I have a little class representing a GUI view, call it View, and ...
user avatar
  • 213
0 votes
0 answers
58 views

Modular design of authentication schemes for a http client

I want to make a httpClient wrapper that is able to use a predefined set of authentification methods: basic, digest, token (oauth), ntlm just to name a few that I will have to implement. My approach ...
user avatar
  • 109
3 votes
1 answer
294 views

Why is it not the case that all d-tors of virtual C++ classes be virtual?

I am basically plagiarizing When NOT to use virtual destructors?. The excellent answers remind us that C++ is pay only for what you use. However, the Standard is a couple of thousand pages long. The d-...
user avatar
  • 6,711
0 votes
1 answer
263 views

Using for_each instead of iterators to avoid iterator invalidation

I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
user avatar
  • 103
2 votes
1 answer
278 views

C++ instance configuration pattern via lambdas

I've been using a "pattern" to configure C++ class instances via lambdas for a while now and I am looking for: an original source & name (I think I read this somewhere, but can't find ...
user avatar
  • 121
-2 votes
1 answer
39 views

Calculating position of menu options with variable sizes

Not entirely sure if this is the most appropriate community for this but... I'm looking for solutions to calculate positions for menu options when the amount of options vary and when each options ...
user avatar
10 votes
6 answers
2k views

Why are people coding "C-style C++"?

In discussions about whether to cast the result of malloc or not when coding C, one common argument is that if you cast the result then you can compile your C code with a C++ compiler. Why would one ...
user avatar
  • 1,398
3 votes
3 answers
733 views

Encapsulation violation

I was going through a question and here the answer says that Encapsulation is being violated class car { int speed; public : int* getSpeed() { return &speed; } }; int ...
user avatar
  • 149
-4 votes
1 answer
127 views

What things should you consider when porting software from python to c++?

Suppose you have written a prototype for an application in python, now you want to rewrite it in c++ for speed reasons and to make a real software out of it. What are things to consider before ...
user avatar
2 votes
4 answers
210 views

A language design with variable qualifier

I am planning to design a programming language. One challenge I face with is whether it is a good idea to have const as a variable qualifier instead of a type qualifier. For example in C++: const int ...
user avatar
  • 29
1 vote
3 answers
179 views

What design pattern to be used for more duplicate elements

I have to create a class named Phone, which can be any phone like Android, iOS and Windows. Again in Android, I will have various types of phones. For me challenge is, I have to maintain more than 100 ...
user avatar
  • 31
-2 votes
2 answers
765 views

Sending float over TCP

I need to send a series of floats over a TCP socket. Firstly, is it safe to assume that most platforms (e.g off the shelf Windows PC/Laptop) and architectures represent floats in the same way (i.e ...
user avatar
  • 133
0 votes
2 answers
124 views

Encoding const-ness on interfaces. Readers - Writers vs Const wrapper

This question is based on this separate question on stack overflow. I have a very low-level structure meant to compactly save presets on flash memory. For simplicity I am going to use stored_record as ...
user avatar
1 vote
1 answer
134 views

Array Declaration for Embedded System

I am developing a library for an embedded system with very little storage in C++. I would like to declare an array for a specific use in one function, however I am unsure if I should declare this in ...
user avatar
  • 21
-4 votes
1 answer
80 views

What is best design pattern to simplfy class with a lot of options to create it?

I have a base class [for example]: class base { private: std::string name; public: virtual void set_name(const std::string& name) = 0; virtual std::string get_name() const = 0; }; ...
user avatar
  • 109
9 votes
4 answers
752 views

Why does C++ have classes?

The title is deceptive; the question is really "why does C++ have classes and not only structs?" Often, people ask why C++ has structs if they are functionally equivalent to classes. The answer is (...
user avatar
0 votes
2 answers
374 views

Is it good practice to throw exceptions in parsing functions

I basically read across the entire internet that exceptions are bad, slow and should be avoided whenever possible. This confuses me because I thought I have a "valid" case to use exceptions. Consider ...
user avatar
2 votes
4 answers
484 views

Wrapping 3rd party library - avoiding leaking abstraction

I'm currently developing an application using SFML. My biggest concern at the moment is making a layer of abstraction over the library, so I can easily change it to something else if needed. What I'm ...
user avatar
  • 203

1 2 3
4
5
53