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
2answers
212 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
121 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
77 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
0answers
41 views

What to consider when designing a collection of traits (C++) [closed]

I'm weighing several different designs for a low-level raster graphics manipulation library. In particular, ways to represent the multitude of pixel formats. I have several approaches, but two of ...
2
votes
4answers
157 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
86 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
158 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
113 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
61 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
70 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
525 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
114 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
103 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
33 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
183 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
58 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
93 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
74 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
66 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
78 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
139 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
78 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
136 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
132 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
95 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
161 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
17 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
195 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 ...
2
votes
1answer
65 views

Publisher-Subscriber architecture with central registry

Problem description Publisher-Subscriber architecture with a central registry where agents can either promote their capabilities or search for a given capability. The project must be developed with ...
-2
votes
3answers
73 views

Accessing one class variable from another class in C++

Suppose I'm in some function of class A, in this function I define an object of class B, say b, and call some function using b.func() which updates some values and arrays, say x and A. Then, I create ...
1
vote
3answers
160 views

What is the best object-oriented design approach for a tree with two node types?

I have a tree-like structure as shown in below picture (as one small example). The tree consists of two different node types, that are: Data Nodes: These nodes that are colored in yellow contain ...
1
vote
1answer
59 views

Handling background tasks that may not be relevant when they are completed

Imagine the following pattern: you have a window with information that needs to be updated asynchronously. You launch and detach a thread to handle fetching the information, but while the information ...
-4
votes
2answers
117 views

Why is C++ not updated as frequently as Java? [closed]

Java was last revised in 2020, while C++ had it's update back in 2017
0
votes
1answer
87 views

To structure big and expandable project(s)

TLDR with bold I want to create a library (I think this is the right term) for my own reinforcement learning environments (envs for short). Most of the envs would be based on self-implemented games ...
0
votes
2answers
150 views

Should I use a class with only static members to encapsulate my program?

So I'm writing a network simulator in C++ as part of a university project. Right now, I have a class structure that looks something like: //includes type aliases #include "GlobalTypes.h" //main body ...
5
votes
1answer
217 views

The case against path expressions in #include directives

I am preparing for a discussion with my fellow programmers which will be about their use of the C/C++ #include directive. The codebase which I have to retrofit to Automotive standards is using ...
4
votes
3answers
354 views

How to know where to draw the line between “safe” code and “over-engineered” code?

Suppose I have a class Texture that will be passed to a Renderer to be displayed on screen. One possible design is as follows: class Texture { public: Texture(unsigned w, unsigned h) : w_ {w},...
2
votes
1answer
287 views

How can malware run on a pc when installed?

I had a quick question. I was working on understanding malware and then I started to wonder how was malware able to run on its own when installed? So for example, I was to click on a bad link that ...
-1
votes
2answers
152 views

Will compiled python code be as fast as compiled C++ code?

I know that Python is an interpreted language and that c++ is a compiled one, or at least I like to think that I've understood some of their differences. Although C++ is apparently faster than ...
2
votes
0answers
80 views

How to separate a serialization code from application in a large c++ project

I'm working on a fairly large c++ project which uses boost's serialization. The issue that I have with the way it is currently organized is that serialization is weaved into the main source code on ...
1
vote
2answers
105 views

How to create objects and allocate data only once in C++ to improve speed with octave .oct files?

I have been coding some octave .oct files lately (C++), and for my purposes speed is of the essence. It seems to me that creating C++ objects (in general) can take some time. I was wondering if ...
2
votes
1answer
109 views

Is it common to include a specific build of a library/ tool for production level project?

I am working with C++ in a Linux/ Unix environment. I am trying to learn the physical design of large scale projects. In one of my projects, I am using an SDK from a camera manufacturer. They released ...
30
votes
5answers
8k views

Is there a way to use a C++ API in C#?

I want to code a little program that takes in head tracking data and moves a 3D object accordingly on the screen. To achieve this I found a software called opentrack that has a C++ API. The problem is ...
1
vote
1answer
81 views

How to make a system of mutually related classes?

I am making a C++ glfw wrapper for myself to use. I want to have classes like Monitor, Window, Context that would be wrappers for glfw objects like GLFWMonitor* or GLFWWindow*. The problem is that if ...

1
2 3 4 5
49