Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c++]

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

14
votes
7answers
6k views

Is it a bad idea have make a class method that is passed class variables?

Here's what I mean: class MyClass { int arr1[100]; int arr2[100]; int len = 100; void add(int* x1, int* x2, int size) { for (int i = 0; i < size; i++) { x1[i] +...
0
votes
1answer
28 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 ...
9
votes
1answer
152 views

Using friend classes to encapsulate private member functions in C++ - good practice or abuse?

So I noticed it's possible to avoid putting private functions in headers by doing something like this: // In file pred_list.h: class PredicateList { int somePrivateField; ...
-1
votes
2answers
112 views

What are the advantages of proxy classes?

I've been learning about proxy classes in c++. I really don't see the advantages of using proxy classes, as they're not any better at concealing information than private members are. What advantages ...
2
votes
2answers
109 views

Primitive type conversion in computer graphics

I have been repeatedly told that explicit type conversions are an indicator of bad code and they should be avoided. Now in all honesty I have been annoyed a bit by these claims due to the nature of ...
0
votes
1answer
49 views

Is it better to initialize semaphores in shared memory or give them as command line arguments? (C++)

I am on a project for which I have to spawn many different processes, all in different executables, and there will be some shared memory segments and some semaphores to synchronize them. I use an "...
-2
votes
1answer
96 views

How to organize the build system of a project as it starts including multiple languages across multiple operating systems and compilers?

I wrote a Music Player and Library in Java for GNU/Linux and Windows. My build process is currently in ANT, but I intend to migrate away from that to something more modern after the next release. I'...
0
votes
0answers
33 views

What is the best way to get directX (2d and/or 3d) to draw in a XAML C++ class?

I'm trying to figure out the best way to draw some plots and I don't even know if I'm asking the correct question. So if I'm not please let me know if I'm not even on the right path. I'm building a ...
7
votes
2answers
357 views

Class that returns multiple unrelated values, are there better way to accomplish this?

I have a "tracker" class. This class tracks objects from a given input image. But in addition to this, there is another parameter that corresponds to a value used in generating the image. The ...
5
votes
3answers
364 views

Is it okay to start a thread from within a constructor of a class

This is purely a design philosophy question in the context of C++. Is it a okay design philosophy to start a thread from within a constructor? I have a library whose sole responsibility is to ...
1
vote
1answer
106 views

How to understand and design functions with enumeration arguments that work in tandem with bitwise operators in C++ and Qt?

In the C++, there are 6 bitwise operators: Symbol Operator & bitwise AND | bitwise inclusive OR ^ bitwise XOR (eXclusive OR) << left shift >> right shift ~...
3
votes
1answer
104 views

Should I specify my header include path in the source code, or as a project option?

Basically, I am asking, whether my code should say #include “../libs/src/my_lib.h” or #include “my_lib.h” with a complier option of -I ../libs/src/ I feel (reasonably strongly) that ...
1
vote
2answers
149 views

Include own header file first or last? Any technical reasons?

I was revisiting my question How can I prevent header hell?, when I noticed a comment which said A good technique for ensuring a header is independent is having a rule that the source file always ...
-2
votes
0answers
41 views

Passing member variable as argument into member function vs. some other alternative [C++ & Python] [duplicate]

In a Python class, say it's called some_class that I have written, it contains a member function some_function(self,u) that takes in some argument u. This class also contains a member variable u. I ...
-4
votes
1answer
71 views

Inheritance of Constructors from parent into child class [closed]

Is the Default Constructor of Super or Parent class Can be Inherited into Child class ?
0
votes
1answer
170 views

Is it a good idea to make huge objects dynamic in C++? [closed]

I have an engine and if I want to use the 3d system I always have to pass a pointer to any mesh renderer. If I would make the 3d system static then I just could use them. But the 3d system is big with ...
3
votes
3answers
127 views

Factory pattern or builder pattern ? which one is suited for reading Finite Element Model data from a text file?

A follow up to another question (Making a design decision about reading model data from an input file). I wish to ask another question regarding builder or factory pattern. (I read that builder is ...
1
vote
1answer
94 views

Best practice of c/C++ dependency management on build servers?

I develop largely in java which has maven or ant/ivy. Is there a recommended way to manage build dependencies for c++ projects? I'm setting up the build on our build server right now but the thing ...
2
votes
1answer
81 views

Making a design decision about reading model data from an input file

I am writing a finite element software in C++ and Qt. I want to load the input data to the model. I have a Model class that holds the data and does the work. I have created a simple lexer and parser ...
2
votes
1answer
154 views

What are the pros and cons of keeping most of an application's state in a single struct?

In my application, I have a few classes. Many of these classes share common state like a reference to the logger for example. For example, both A and B require some common state to get their job done. ...
5
votes
3answers
267 views

Does the output of a compiler depend on the OS you are using?

In the company I am working in we have a management software, written by an external programmer. Let's call the software PK. PK was initially written in the 90s using C++. Since then it was regularely ...
1
vote
1answer
63 views

Managing a third party library that is used by multiple independent libraries

I am working on configuring the build environment for a C++ project that uses multiple libraries. These libraries are independent of each other, but they all depend on the same 3rd party library (...
0
votes
1answer
131 views

C++ naming convention for files within namespaces

I am currently working on a C++ project with a source file structure like this (headers excluded): src/ ├── namespace1/ │ ├── namespace1_base.cpp │ ├── namespace1_derived1.cpp │ └── ...
2
votes
1answer
161 views

Architecture for messaging library C++

I have a library, which sends and receives a set of binary messages and parses them. So far I’ve used inheritance for my design, i.e. class BaseMsg { // init msg from rx'd binary stream ...
3
votes
2answers
206 views

C++ Gof Design Patterns heavily depends on new or shared_ptr

I'm trying to learn the best practices for code design and reuse in C++ so I am going through the well known GoF Design Patterns Elements of Reusable Object-Oriented Software. I noticed that nearly ...
2
votes
4answers
161 views

Inheritance: When only some concrete objects need to share state

I have a series of classes that represent widgets in a layout system. The base class for all of these concrete widget types is Widget. If I have a Button and a Text Box, these both derive from Widget. ...
0
votes
1answer
40 views

How to manually model a UML activity Diagram to JSON with Qt C++?

Suppose I have a kind of UML activity diagram with 1-n forks and joins. The assignment of the individual nodes relative to each other is defined by an XML relationship table via UUIDs where each ...
1
vote
1answer
62 views

Binary Search Tree with ID and Duplicate Values

I'm having trouble finding resources for this implementation I'm trying to figure out. I want to save nodes in a binary search tree (self balancing) containing an ID and value struct Score { int ...
1
vote
1answer
198 views

C++ immutable struct

I would like to be able to implement immutable data in C++. In short, given a C++ object in which I would like to modify a member variable, instead of modifying that member in place I would like to ...
2
votes
2answers
129 views

Can nested loop have linear time complexity

I was going through the traditional quick sort algorithm. I had a look on the partition algorithm in a couple of places and the implementation difference was very subtle. Here are the 2 approaches: ...
6
votes
4answers
344 views

Software design meeting procedures

Elements of my team and myself are experiencing some difficulty performing design meetings. The symptoms are: We get off track easily, a combination of low understanding of the content of the system ...
0
votes
1answer
50 views

Data Structure to join points by similarity measure

I have a series of points (x,y) and each point has a colour (in the LAB colour space). I need to associate points by similar colour and then spatially. So the end result is each point becomes part of ...
2
votes
3answers
324 views

From a language design perspective, is the reference type in C++ mis-designed

Besides the fact that all primitive types of C++ are copy assignable except the reference type, it also doesn't play well with containers or any other parts of the language where copy-assignable ...
-4
votes
2answers
130 views

Can derived class be singleton? [closed]

I need to have some common functionality while the derived class needs to have singleton behavior. For example: class A { //common file functions } class B : public A { //Needs to be singleton . ...
0
votes
2answers
151 views

How do you actually access the data of individual components in an Entity-Component-System design? (C++)

I've been scouring information on Entity-Component-System designs for weeks to try to figure out how to implement it in C++, and there are lots of wonderful explanations for different aspects of it, ...
-1
votes
1answer
95 views

Differences between branching and virtual methods

I was trying to find more info on the matter but could only find this: In C++ why and how are virtual functions slower? The answer says that the virtual call "Get[s] the right function address from ...
41
votes
5answers
9k views

How do variables in C++ store their type?

If I define a variable of a certain type (which, as far as I know, just allocates data for the content of the variable), how does it keep track of which type of variable it is?
-3
votes
2answers
171 views

C/C++ code optimization without compilation

Given a simple loop in C or C++ such as the following: for (int i=0, j=0; i<5; i=i*2){ j=j+i*1; } I would like to use a tool (gcc, clang or any other) to optimize the code without actually ...
0
votes
2answers
73 views

Abstract function declaration in C++

I am a beginner in C++. I'm currently experimenting with the Chromium source code and have noticed the following: For many of the cc files, there exist an h (header) file which is imported by the cc ...
0
votes
2answers
96 views

C++, Threads, Classes and Conflicts

This is a concept related question. I'm writing a program polling for alerts on various devices, there are two different type of alerts i need to poll, reds and oranges. My approach is to create two ...
0
votes
1answer
94 views

freeRTOS C++11 queue with pointers inside, object-oriented

I thought about this problem I was having. I have producer-consumer type of design with two user-created-tasks sender, and reader. Queue is used to communicate between reader-sender. Currently the ...
3
votes
2answers
138 views

Should I use a unique_ptr with an array type, or a vector?

I've been out of C++ for years, last time I used it was back in gamedesign before C++11. I see all these new pointer types which seem great. But I'm unsure when and how to use them. In the old days I ...
0
votes
1answer
85 views

C++11 freeRTOS questions about queue usage and object design

Background I'm writing C++ firmware with freertos to penplottingrobot. It's a makeblock XYplotter and the firmware is connecting to mDraw software for command instructions thru USB drivers. MDraw ...
22
votes
6answers
1k views

continuous integration for scientific software

I'm no software engineer. I'm a phd student in the field of geoscience. Almost two years ago I started programming a scientific software. I never used continuous integration (CI), mainly because at ...
2
votes
0answers
70 views

Dynamically load user code from a common library

My project aims to provide a common interface between multiple different HDL simulators, so users can write test benches that will work no matter the simulator used. In this situation, it is the ...
2
votes
2answers
284 views

Is the meaning of `const` still thread-safe in C++11?

I recently came across Herb Sutter's video from about how the meaning of const and mutable has changed in C++11 to mean bitwise const (and thread-safe, as a consequence) instead of the traditional ...
0
votes
2answers
93 views

Design a tree-like hierarchy of ownership classes

I have a class, call it App, that will instantiate and own a set of classes of type Agents, each of which will instantiate and own a set of Listeners. Ownership is unique and non-transferable, hence ...
2
votes
3answers
237 views

Why is the Command desing pattern useful for game AI?

I'm trying to learn the Command design pattern and apply it to the game I'm working on. First I read about the general implementation, and I feel like I understand it pretty well. Now I want to know ...
0
votes
1answer
111 views

Orchestrating Object Instantiation and Intercommunication

We have a C++ project managed by UML software, which generates code for instantiating and passing data between objects. Unfortunately, this software adds a lot of overhead to our builds and ...
2
votes
2answers
76 views

Separate variable value from error code using struct

Let's say I have a function that calculates a sensor output, all values are >=0, but also I have to detect some error situations like "NO_POWER" which I encoded with value "-65500". On my application ...