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
0answers
37 views

C++ pattern for compile-time configurable class functionality

Due to resource limitations (embedded), I want to make some functionality that a class provides optional. The decision to include this optional functionality should be made at compile time. For ...
-2
votes
0answers
52 views

Is there any tool which helps to find One Definition Rule violations in C++? [closed]

Is there a tool which helps to find One Definition Rule violations automatically?
0
votes
0answers
53 views

Design pattern for exposing static functions in C/C++ only to unit tests [closed]

I have some static free functions (the don't belong to a class) in a C++ file. I want them to still be only visible within such module and to be free, but I want to test them with unit tests as well. ...
0
votes
0answers
11 views

Can I mix static and dynamic libraries? [migrated]

I want to build a library which requires several other libraries, that I also need to build. Does it make a difference if I build some of them as static libraries and some of them as dynamic libraries,...
-4
votes
1answer
77 views

Exiting Recursive Function C++ [closed]

In the following function IsDoubleString(),if res is true then it shouldn't call IsDoubleString(), I debugged the code but I am unable to understand that once it hit the line returns res; why does the ...
1
vote
2answers
191 views

Minimizing code duplication without using macros or sacrificing speed

Here's a snippet of code: An inlined function: inline void rayStep(const glm::vec3 &ray, float &rayLength, const glm::vec3 &distanceFactor, glm::ivec3 &currentVoxelCoordinates, const ...
0
votes
0answers
80 views

C++ loose coupled library design [closed]

Let's see if I can explain this properly. I have been told to refactor/redesign/rewrite a desktop application. I am starting by the library part first. Everything is C++. I came up with a new design ...
0
votes
0answers
32 views

Which components of an HTML Element, can I assume will be static over the course of its lifetime?

This is a question for people who are familiar with how HTML typically is built and behaves on webpages. Backstory and requirements I am building an HTML tracker with a C++/Qt backend. I am trying ...
0
votes
0answers
56 views

Using virtual inheritance for an interface system based on abstract classes

I want to use a physics engine (like bullet or PhysX) in my program, however I want to hide the actual physics engine from it, so I can easily swap it out with another during run-time (e.g. switch ...
0
votes
0answers
12 views

Online Game (Multi User Dungeon) - is it possible to avoid global data? [migrated]

I need your precious advices :-) I am currently designing a Multi User Dungeon (MUD). For those who do not know what it is, they are the ancestors of MMORPGs. There is no graphics, everything is ...
1
vote
3answers
65 views

Handling errors in looper/event loop interface

I have a C++ class that spawns a thread that contains an event loop of sorts and the class provides an API to query the list of events that have occurred since the last call, i.e something like std::...
0
votes
4answers
176 views

Can int16_t be easier on the processor then int?

I know that the compiler and architecture of a processor also have a role to play in this. But this is more of a "can it" rather then a "does it" question. I have already tried to research this, but ...
8
votes
1answer
386 views

How can I optimize a program's performance when no profiling tools are available?

I am currently working on an OpenGl program whose performance I would like to improve. The performance is okay but not ideal on powerful dedicated GPUs, but is abysmal on integrated graphics (< 10 ...
0
votes
1answer
104 views

C++ Factory for Polymorphism + Templates + Smart Pointers [closed]

I'm trying to build a Factory class so I can: Builder* x_builder = BuilderFactory::create("X"); vector<unique_ptr<XItem>> x_items; x_builder->build(&x_items); Builder* y_builder = ...
2
votes
1answer
98 views

When developing for C++ in Visual Studio, is there a quick way of being able to test your code as an exe and DLL?

I'm developing some C++ code that eventually will be compiled as a DLL to be accessed with Python through CTypes. My workflow is generally that of compiling the DLL and running the Python script ...
0
votes
2answers
255 views

Dependency Injection in C++ use pointer or object?

While I am learning C++ based on how develop in modern PHP frameworks I decided to use the Dependency Injection pattern with services as Singletons. For making myself clear let suppose we have the ...
0
votes
0answers
99 views

multithreading - waiting on a condition without using locks (c++11)

i've been wondering about it for a while now but never found any answers. is it possible to use something like a condition variable without a lock? I have a vector of objects, and a thread pool, and ...
5
votes
3answers
293 views

How should a derived class be tested?

I have a question regarding proper design of tests. Suppose that there is a class A class A{ public: virtual int methodA(); virtual int methodB(); virtual int methodC(); ...
4
votes
4answers
1k views

How to check whether existing code base can deadlock

I'm improving/expanding a somewhat large code base, and I've introduced multithreading into it. But with the possibility of introducing code that could deadlock, which is nigh impossible to test for ...
-3
votes
3answers
252 views

Is it an ok practice to keep pointers dereferenced?

For me, I prefer having all my variables, not as pointers. Is it ok to keep all heap-allocated variables dereferenced? For example: #include "Foo.hpp" #include "Bar.hpp" class Foo { private: Bar* ...
0
votes
1answer
201 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 ...
1
vote
3answers
166 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 ...
0
votes
2answers
463 views

How to prevent 'global variables' in a big project?

With 'global variables', I mean Variables on namespace level Static data members in classes Static variables in functions In a big C++ project I would like to have a mechanism (like a compiler ...
9
votes
9answers
688 views

Inheritance vs Composition For Chess Pieces

A quick search of this stackexchange shows that in general composition is generally considered more flexible than inheritance but as always it depends on the project etc and there are times when ...
1
vote
4answers
197 views

How would I add up enumerator values such that any combination provides a unique number?

Backstory (You can skip) I am writing a pronunciation library for irregular words. Take something like the following: T1E1s // tee one E one es | tee one E ones 1994-1995// 1994 (minus|dash|to|) ...
0
votes
1answer
81 views

What OOP design pattern would work best for an overseeing class connecting related objects enforced at compile-time?

The Problem I would like to create a managing "overseer" class that connects several related object groups together where any particular group is able to be easily swapped for another using C++11 ...
2
votes
5answers
467 views

Advantages/Disadvantages of Compiling as Both C and C++?

So I've seen some C libraries written so that they compile without any changes with a C++ compiler, for example Lua. What are some advantages and disadvantages of doing this? A few basic ones I see ...
4
votes
2answers
2k views

C++ : What is the order of function pointers inside vtable?

In this answer to "In C++ why and how are virtual functions slower?", the author mentions below point: "Get the right function address from the vtable into a register (the index where the correct ...
1
vote
2answers
232 views

How can I make dll that can be called from several programing languages?

As of right now I am building authentication library for let's say programing site(It needs to be included in the program). The problem is that there several languages are used and I want to make ...
1
vote
1answer
95 views

Architecture/Design for Hardware Control Software

I'm currently working on the control software for a system that includes a lot of user controllable hardware and also has many configurations. Configurations in this context refers to a specific ...
2
votes
1answer
76 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 ...
-4
votes
2answers
152 views

What is the proper way to unspecify an integer's value in C++? [closed]

// Default initialization int i; // i has an unspecified value return i; // Probably 0, but Unreliable i = 5; // i has a specified value i = int();// This will give it a specified value, 0 i = ...
2
votes
1answer
120 views

C++ design pattern for template instantiation based on run time information?

Say I want to be able to create objects for a range of template parameter template<int a> class Myclass : public MyclassSuper{...}; And I want to create objects like Myclass<...
5
votes
1answer
308 views

What is the right way to create a build system?

I'm a student, and I don't have much expirience with the building process. In the last few days i've read something about CMake and others build system generators, but other than that I don't know ...
3
votes
1answer
94 views

Design Review Of SOLID Principles For An Autonomous Mobile Robot

I am self-learning robotics, C++ and good object oriented design. I have asked various questions over the past couple of weeks: 1 and 2 that have lead to the following design. The design goal is for ...
2
votes
1answer
166 views

Would de-coupling using interfaces/templates make the system easier to maintain at the cost of over-engineering?

I have been practicing this hybrid approach for dependency injection in the last couple of days and I am wondering if it should also apply to components which are within the same package? For example:...
0
votes
1answer
122 views

How can I vary the distance function in my code?

I have a simple design question. I have a tree based C++ class. It needs to use a distance function in order to calculate nearest neighbors. But the distance function is available from an external ...
6
votes
1answer
297 views

Is it better to use lambda functions or boolean variables to record state

I have heard some people claiming that boolean state variables are generally bad and should be avoided when possible. Apparently in many cases it is possible to put state into lambda functions, ...
2
votes
1answer
114 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 ...
1
vote
4answers
211 views

Should I always use iterators when working with strings?

Here is the known old way to iterate over the string: for (int i = 0; i < str.length(); i++) { char c = str[i]; } However recently I have also seen in multiple places the usage of ...
2
votes
1answer
100 views

Design approach for extending class functionality - Embedded C++

For my company i am refactoring our embedded C/C++ code base to increase re-usability for commonly used functionality. Currently i am refactoring our command line interface but i ran into a design ...
2
votes
2answers
196 views

Should smart pointers be exposed in a C++ API?

Exactly as the name says, should smart pointers be exposed in a C++ library API? I've used quite a few C++ libraries and haven't ran into exposed smart pointers yet. Given that it's very common to ...
3
votes
2answers
294 views

What is the difference between a static library and an archive library?

In the comments of a recent answer, I equated a static library with an archive of compiled object files. The response was that they are not the same, so what is the difference? To clarify - gcc ...
-2
votes
1answer
146 views

How to obtain and store a subgraph of a graph in C++?

I have implemented a graph structure (for graphs having ~30,000 nodes and ~300,000 edges) as follows: class graph; class node; class edge; class graph { public: graph(){}; vector<node*> ...
0
votes
1answer
178 views

Network programming (boost::asio), architecture and communication protocols

I'm trying to make a simple network application using boost::asio. I think that I understood the basic things like io_context, async functions etc, but I really don't know how to deal with buffers. ...
1
vote
1answer
72 views

Library with different runtime behaviour based on usage history (design question) [closed]

I want to design a hash table library that keeps usage statistics and based on how it is used will use different implementations at runtime. For example use a certain implementation for small size ...
6
votes
1answer
239 views

What is the best way to handle glue between different classicly OOP objects at the higher levels of abstraction?

In object oriented programming, it is commonly said that each class/object/instance should have a well-defined purpose. For example, there may be a Window class in a windowing toolkit, a ChunkLoader ...
4
votes
3answers
412 views

How to reach the parent object?

I have a parent object that has some other objects as fields. The parent object fully owns these fields: they can be declared as fields of the parent object (MyPart part), directly, not as references. ...
5
votes
1answer
393 views

Is there any reason *not* to forward declare all forward declarable function parameter/return types?

I ran into a situation where my build speeds have started to become large and have affected productivity. I had already minimized header dependencies before using forward declarations. Now I've ...
2
votes
1answer
118 views

How to write a class that uses other classes but needs the same functionality - should I just wrap around the methods?

I want to create a class ProcessHandler for Windows that pretty much uses the WINAPI. The class ProcessHandler should be able to scan memory, emulate keyboard and mouse, needs some DLLInjector, some ...