Questions tagged [c++]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
20 views

What is the point of inheritance in c++ programming?

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; ...
2
votes
3answers
72 views

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

The question pretty much says all, but let's look into a simple example: So, let's say that we have a functor that outputs many objects (e.g. as a tuple). Is it a good idea to store the outputs to the ...
-4
votes
0answers
48 views

How can I create a unique hash for 3 dimensional vectors? [closed]

I'm trying to fix a bug in code I'm maintaining where non-unique hashes are being generated due to an inadequate hash function. Background The code is attempting to store 3D vectors that are identical ...
0
votes
2answers
106 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 ...
2
votes
1answer
82 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 ...
0
votes
1answer
80 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(...
0
votes
1answer
80 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? #...
4
votes
1answer
99 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 ...
5
votes
6answers
408 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++. ...
0
votes
1answer
52 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. ...
1
vote
1answer
327 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....
1
vote
1answer
149 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 ...
0
votes
0answers
43 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 ...
3
votes
1answer
170 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-...
0
votes
0answers
72 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 ...
2
votes
1answer
81 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 ...
-2
votes
1answer
34 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 ...
7
votes
5answers
712 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 ...
3
votes
3answers
221 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 ...
-4
votes
1answer
102 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 ...
2
votes
4answers
169 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 ...
1
vote
3answers
93 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 ...
-2
votes
2answers
168 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 ...
0
votes
2answers
115 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 ...
1
vote
1answer
67 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 ...
-4
votes
1answer
74 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; }; ...
7
votes
4answers
595 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 (...
0
votes
2answers
119 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 ...
2
votes
2answers
112 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 ...
0
votes
1answer
35 views

commonly used practices for deploying package primarily composed of bash scripts

I am working on a tool that primarily uses bash scripts and C++ code. Generally I have experience with basic tools written in C and C++ in which we can have a build system like ./configure; make; ...
3
votes
3answers
184 views

Should you define an equality test solely for testing?

Assume you have a class C. C defines a public method (member function) C::m1. Calling c.m1() (c is an instance of C) can either Return after mutating the object c it was called on. Throw an ...
-4
votes
1answer
64 views

Using only the Cache not the DRAM in a Program (USB to Ethernet) [closed]

I am reading some data from USB, do some packet processing and then send the result to the Ethernet port. The USB ports are connected to an onboard USB Hub where it communicates with the ...
1
vote
1answer
95 views

Is there a standard technique to implement command line options within programme for CLI?

I am writing a command line tool in C++ that takes several arguments, some of them file names but also option parameters. Is there a standard way to parse and implement these options? A simple way ...
-2
votes
1answer
76 views

Are jagged arrays lvalue or not?

When I was study lvalue i see that C expression can be lvalue if a subscript ([]) expression that does not evaluate to an array. (from https://docs.microsoft.com/en-us/cpp/c-language/l-value-and-...
0
votes
0answers
67 views

How can you multithread an html parser [ in C++ and similar languages ]?

Ive done two HTML parsers. Done with Regular Expressions [that accounted for nesting]. It was quick, but error prone. Done by evaluating Character by Character through switches. Here was the basic ...
0
votes
1answer
79 views

How to define values dependant on the derived type?

My base class must provide an interface to get a value that is dependent solely on the type of the derived class. I can think of two ways of implementing this: Solution A, virtual functions: class ...
0
votes
2answers
145 views

In C++, Why do bitwise operators convert 8 or 16 bit integers to 32 bit?

Is there a logical reason why the integer is upgraded to 32+ bits? I was trying to make an 8bit mask, and found myself a bit disappointed that the upgrade will corrupt my equations. sizeof( quint8(0)...
-3
votes
1answer
50 views

In C++, does it make sens to have library project be composed of other libraries?

I'm working on a C++ project which is currently divided into "sub modules" / "components". Each of these are compiled into a separate library (components are usually 10-20 files). The libraries are ...
1
vote
1answer
37 views

Writing a data-oriented ECS update loop that handles multiple components

So I have an engine in progress that's structured like this: entities are simple ids (unsigned short) components are stored in pools which are static members systems are stored by the manager, and ...
-2
votes
1answer
80 views

Designing a sqlite component in C++

I work on a small component in an embedded device (sensor). This component : Every 5 seconds, sends requests to other components using sockets (get health check status, operating status etc) and ...
0
votes
1answer
100 views

How to avoid messy code when working with different libraries

I'm planning to work with different libraries that use different conventions. One uses snake_case, another one uses camelCase. This leads to code that looks like I can't make up my mind: Some_Result ...
57
votes
11answers
13k views

I never use pointers in my C++ code. Am I coding C++ wrong? [closed]

This question may sound strange to you, but I am learning C++ all by myself. I have nobody whom I could ask for mentoring and I would be very glad for some advice. I have started recently to program ...
0
votes
1answer
141 views

What's the added value in the sophisticated use of C++ templates advocated by Alexandrescu and others?

In general terms, what's the added value in using the techniques described in the iconic book "Modern C++ Design"? Is it simply the ability to write reusable code that's easily extensible? Or are ...
-2
votes
1answer
78 views

Best way to pass an optional parameter to a program

In a couple of my programs, the program needs to know an IP address and a port to which it should connect or send data to. The solution I have right is to ask for user input via the console - but ...
2
votes
2answers
134 views

How can I improve this design to achieve a more loosely coupled system and better testability?

My question I built an inverted pendulum on an Arduino using C (ie. everything was done procedurally). I'm trying to self study application design and would like to refactor my code into a more OO ...
-1
votes
1answer
97 views

Do other languages have variables shared between threads?

I guess it would be too complex for Node.js / JavaScript to leverage, but I've been working with clusters in node to break big tasks down so all cores can work at once but the inter-process messaging ...
-1
votes
1answer
170 views

fake filesystem for unit tests

I am writing an application in c++ and Qt5. It would be very convenient for me to create a virtual file system so I can unit test code working on files. I have found that in Qt4 there was a ...
0
votes
0answers
18 views

How to design an openCL program when the size of the input is much greater than the workitems

This is a question about design, the use case below is more of an example explaining problems and constraint. Also I'm trying to get more experience with parallel programming so forgive me if my ...
5
votes
1answer
199 views

Procedure for migrating a large C++ code base to use smart pointers

I am in the process of refactoring a large C++ code (~2300 files, ~600K lines, mostly older C/C++98 style code) and there are definitely memory leaks that could be shored up using C++ smart pointers. ...
2
votes
1answer
111 views

C++: Achieving a decoupled “Definition is Registration” paradigm for derived classes?

I'm trying to engineer this: 200 subclasses [ Derived Classes ] After a subclass is defined, I wont need to edit any other file. [ Decoupled ] Subclass Definition registers itself. [ Definition is ...

1
2 3 4 5
50