Questions tagged [c++]

C++ is a general-purpose programming language. Use this tag for questions about/utilizing C++. Do not also tag questions with [c] unless you have a good reason. C and C++ are different languages. Use a versioned tag such as [c++11], [c++20] etc. for questions specific to a standard revision.

Filter by
Sorted by
Tagged with
0 votes
0 answers
17 views

Error: "No such file or directory" when including OpenGL's freeglut.h in C++ project [Visual Studio Code, Windows]

I'm new to C++ and now I'm trying to include external library. I'm facing an issue while attempting to include the OpenGL freeglut header in my C++ project using Visual Studio Code on Windows. I ...
Retard Programmer's user avatar
0 votes
0 answers
64 views

Should i free some std::vector<> inside a c++ class? [closed]

I am writing an SVM classifier in C++ and so far i've declared the class as follow: #ifndef BINARY_SVM_H #define BINARY_SVM_H #include "kernels.h" #include <string> #include <...
Niccolò Tiezzi's user avatar
0 votes
0 answers
67 views

How to avoid std::async memory leak when the process terminates quickly

If after starting a thread via std::async you immediately exit it and then exit the program, then sometimes the thread code does not have time to complete to the end (the thread does not have time to ...
Alexovsky's user avatar
-1 votes
0 answers
27 views

In MOBA game servers, when a cyclic timer experiences a delay, what is the most suitable way to calculate the next occurrence time? [closed]

There are three approaches: Catch up: nextWhen = when + period; Delay: nextWhen = now + period; Smooth frame skipping: nextWhen = when + period - (now - when); if(when < now) when = now + period;...
likecpp's user avatar
  • 19
0 votes
0 answers
47 views

std::function - function uses ‘auto’ type specifier without trailing return type in C++ 11 [duplicate]

I'm trying to get a C++14 library working with our C++ 11 code base and having trouble with using std::function (of which I know very little). Minimal code: #include <functional> #include <...
Danny's user avatar
  • 2,538
0 votes
0 answers
74 views

`if constexpr` does't compile with `avr-g++ -std=c++17` [duplicate]

In a method in a class I'm working on I have template <typename T = int_fast16_t, uint8_t Bits = sizeof(T) * 8 - 2> struct FixedPointFraction { using value_type = T; constexpr static uint8_t ...
Petr's user avatar
  • 62.8k
0 votes
0 answers
8 views

Using OpenXLSX with C++ -> how to set a cell color

I have OpenXLSX with C++ and I can write data to the cells. Everything works perfectly. But I can't find a way to set a color for a cell. When I search for this problem, I find a lot of solutions for ...
BigGreatZero's user avatar
0 votes
0 answers
23 views

How to restrict clang half precision float code generation to NEON only?

I've been building fp16 enabled applications on clang using the compilation flag of -march=armv8.2-a+fp16. The HW capabilities are tested using getauxval(AT_HWCAP) & HWCAP_ASIMDHP -- which gives ...
Aki Suihkonen's user avatar
0 votes
0 answers
38 views

c++ std::scoped_lock Caller failing to hold lock 'lock' before calling function 'func'

In my project I'm returning a std::scoped lock to guard some resources. A very simple example is this // Type your code here, or load an example. #include <mutex> class A { public: ...
JHeni's user avatar
  • 491
-5 votes
0 answers
38 views

Knapsack problem with an additional condition [closed]

Can you help me with changing the program code? Link to the task description: https://rosettacode.org/wiki/Knapsack_problem/Bounded Link to the solution of the problem using the dynamic programming ...
by_your_side's user avatar
1 vote
2 answers
74 views

Is it possible to overload the implementation of a pure virtual function in the child class?

I am working on a project in which I have a base class called MSTAlgorithm (Minimum Spanning Tree Algorithm). Two classes called PrimsAlgorithm and KruskalsAlgorithm publically derive from this base ...
Blargian's user avatar
  • 316
1 vote
0 answers
28 views

Why flag "begin" in leveldb WAL is defined as ptr == slice.data()?

This code is in leveldb to get the type of fragment type in WAL Status Writer::AddRecord(const Slice& slice) { RecordType type; // Why not defined as left == slice.size(); const bool ...
王听正's user avatar
0 votes
0 answers
57 views

C++ Why use thread join as opposed to simply calling a function?

Coming from C, I'm accustomed to simply forking a new thread/process (IE, a detach). With respect to C++ thread join, if the calling process blocks until the joined thread has completed, I'm curious ...
Dan's user avatar
  • 1
1 vote
1 answer
52 views

How to use boost graph to traverse a planar graph ( representing a tree ) to simulate walking around the edge of the graph

I have the following graph on the XY plane. Vertices are numbered. I have struct Point { double x; double y; } std::vector<Point> points; std::vector<std::pair<size_t, size_t> ...
bradgonesurfing's user avatar
0 votes
0 answers
25 views

The program I wrote with C++ and socket programming can't clear the message after each message transmission

The 'line' part in the program needs to be cleared after each message transmission, but I haven't been able to do it somehow. #include <winsock2.h> #include <ws2tcpip.h> #include <stdio....
user23044708's user avatar
2 votes
1 answer
86 views

Is the order of an unordered map alway the same for a given compiler?

I just found a bug in my code that depends on the order the elements are stored in an unordered_map. Ok not a big deal, I'm going to fix it. My question is only out of curiosity to understand ...
JRR's user avatar
  • 3,078
0 votes
0 answers
24 views

CMake failed to check C++ compiler with Visual Studio 2015

I'm trying to compile LibTIFF on Windows. The library needs to be built with CMake. I try to build with Visual Studio 2015. But CMake complains "The C++ compiler is not able to compile a simple ...
Cosmo's user avatar
  • 856
0 votes
0 answers
64 views

How to display visual studio 2022 debug console in project exported by Squareline Studio

I have a project exported by Squareline Studio, but it doesn't have a debug console that I can't see something printed for debug. I found that in my computer some Squareline Studio official project ...
Tom's user avatar
  • 473
0 votes
0 answers
22 views

GLFW in docker container through ssh

I'm trying to resurrect some old code, which relies on script with GLFW. Source code for script can be viewed here The problem is, I need to run it inside the nvidia docker container (nvcr.io/nvidia/...
preciselyv's user avatar
3 votes
1 answer
40 views

The tr function does not translate a word, while the translate function does

There is such code: int main(int argc, char *argv[]) { QApplication app(argc, argv); QTranslator translator; const QString dir = "/usr/share/qt6/translations"; if (...
Name Surname's user avatar
0 votes
0 answers
34 views

VSCode does not display error prompts for files with specific names

Visual Studio Code does not display an error message for a file named operator.cpp, enter image description here but in other files, it is explicitly displayed normally. enter image description here ...
Langur's user avatar
  • 1
0 votes
2 answers
38 views

Could two condition_variable.wait_for used with a single lock?

If codes like std::mutex mut; std::condition_variable cond; bool is_ok = false; void func() { std::unique_lock<std::mutex> lck(mut); if (!cond.wait_for(lck, std::...
f1msch's user avatar
  • 585
0 votes
0 answers
76 views

How should I build a type in C++ that obfuscate a secret private value and counts how many times it is exposed at compile time?

#include <iostream> #include <tuple> #include <type_traits> #include <utility> template <std::size_t A, std::size_t B> struct IsALesserThanB : std::integral_constant ...
Jim's user avatar
  • 536
0 votes
0 answers
36 views

Error in VSCode launch.json: "Inputs Property Not Allowed"

I'm developing ROS 2 nodes in C++ and trying to configure a dynamic debugging setup in VSCode using the inputs property in my launch.json. The intention is to enable selection of different nodes for ...
explorer's user avatar
2 votes
1 answer
77 views

What happens if I give a char input to an int datatype in C++? [duplicate]

I have a program in C++ where I want to take an integer input from the user. I am using the cin function. In the terminal, I can still input characters without getting an error. What is the problem ...
wiz's user avatar
  • 37
0 votes
0 answers
37 views

CMake OpenSSL trouble porting a cpp app from OSX to Ubuntu

As it says in the title, I'm porting an OSX C++ application to Ubuntu. This app works perfectly on OSX, but is failing to compile on Ubuntu. Here is my CMake - it is a little weird because I set up ...
Thomas Murphy's user avatar
-1 votes
0 answers
12 views

Omnett MobileNetwork SImulation

The main goal is to simulate a network in which there are 2 stationary nodes 1 and 2 where node 1 sends a message that gets checked by a firewall and when passed it goes to a server which then sends ...
Nadeem Alli's user avatar
0 votes
0 answers
46 views

in-expression compile-time check for constant expressions for older G++

I have the following macros for certain compile-time checks: /* in-expression compile-time check evaluating to 0 */ #ifdef __cplusplus template<bool> struct Chk_sa; template<> struct ...
mirabilos's user avatar
  • 5,150
-1 votes
0 answers
19 views

What data structure does the Source engine use for its nav meshes?

Visualizing the nav meshes used in a game like Team Fortress 2 for example, they look like a quad tree at first, but they have a very un-quad-like network structure, with each node having a unique ID ...
JACKSON's user avatar
-1 votes
0 answers
34 views

Why am I getting "EXC_BAD_ACCESS" when trying to change pointer value in AVL tree | nodeptr->right = newptr |?

I'm new to C++ and trying to create an AVL tree to get some experience. And I'm trying to change the "right" pointer of a node instance with nodeptr->right = newptr but I get ...
iron9fist's user avatar
1 vote
0 answers
48 views

Implementation of a custom zip iterator that works with std::ranges::transform as well as std:::transform [duplicate]

I have implemented a zip iterator, and it works well when used with algorithm functions like std::for_each or std::transform. However, when I use it with std::ranges::for_each or std::ranges::...
Kyoungyoon PARK's user avatar
0 votes
0 answers
41 views

Undefined Reference in SFML [duplicate]

This is my first C++ project with libraries and I cannot figure out how to link the libraries correctly. I've gotten a hello world to work but I can't get a window to open with sfml. I have tried to ...
CosmaDuck's user avatar
0 votes
1 answer
69 views

Using std::vector<int>::back as projection for std::ranges::sort [duplicate]

I was sorting a vector of vectors based on the last element of the individual vectors. But couldn't get it to work. Copilot gave me the following example: #include <algorithm> #include <...
user515430's user avatar
0 votes
1 answer
68 views

Multithreading c++ notify mechanism [closed]

I am new to multithreading Please help in understanding these basic concept. I will try to explain my question with the help of example.you can be brief but any comment will be appreciated. I am ...
AKASH 's user avatar
0 votes
1 answer
105 views

Want to make a function return a vector of arrays in C++

I have made a function that returns a vector of unknown length containing arrays of 64 integers. When I access the vector inside the function, I am able to access the arrays properly. However, when I ...
Random coder's user avatar
-2 votes
0 answers
41 views

Find how many ways to rearrange an array of post-order from a BST for it to form the exact tree before [closed]

I have a tree called Y and I convert it's post-order to an array. Now I have to find how many ways I can rearrange the array so that when I added every element in the array sequentially to a BSTree it ...
tthin_09's user avatar
0 votes
0 answers
45 views

Hiding SQL queries from applications similar to Process Hacker

Currently I'm debugging an issue where the sql queries executed by an Application are visible in ProcessHacker 2 [ Steps - Open ProcessHacker -> Right Click on the application -> Properties ->...
Dev-Geek-2001's user avatar
1 vote
0 answers
21 views

How to set exposure for Still Image capture when using DirectShow API on Windows?

I am trying to use the Windows Directshow API to capture still images using a UVC camera. I am using this article from Microsof(https://learn.microsoft.com/en-us/windows/win32/directshow/capturing-an-...
alok chander's user avatar
0 votes
1 answer
56 views

Why i am getting output in cout (0 16) even i dont enter any input value in cin [duplicate]

#include<bits/stdc++.h> using namespace std; int main(){ int a; int b; cin >> a >> b; cout << a <<" "<<b; } OutPut: 0 16 Your help will be ...
Khan Zahid Rasheed Raja's user avatar
-3 votes
0 answers
45 views

Why won't this validate input [closed]

#include <typeinfo> #include <sstream> std::string Item::getFoodName() { // Store the original value of foodName std::string originalValue = foodName; if (typeid(foodName) == ...
Jacob's user avatar
  • 1
0 votes
0 answers
47 views

How to apply a predicate function for all elements of array/string [closed]

I want to create universal function which returns true if predicate was okay for all chars in string. There is no syntax error, but expected result does not appear. bool checkByProperty(std::function&...
rxvxl's user avatar
  • 1
0 votes
1 answer
26 views

C++ Google Tests and Visual Studio Linker Error

I am trying to write tests using the google test framework for a C++ project of mine in Visual Studio. Here is my current project structure: solution | +-- project | | | +-- src | | | +...
Clement Faisandier's user avatar
-3 votes
0 answers
58 views

Having problems with reading and parsing chats in C++ [closed]

I'm currently adapting and building on my program that reads chats from a .txt file, and allows you to lookup chats, sort them by duration, etc. Currently, I am having trouble with my reading and ...
yuvraj narula's user avatar
0 votes
0 answers
45 views

Optimizing Memory Management for Frequent Tree Updates in C++: Memory Pool vs. Native new/delete Operations

I'm currently dealing with a tree structure implemented using Node objects, and my application requires frequent insertions and removals within this tree. While the number of nodes in the tree doesn't ...
nowox's user avatar
  • 26.7k
-1 votes
0 answers
50 views

I'm trying to make a texture for OpenGL on C++ out of an embeded into the executable BMP and method GetDIBits fails and returns 0

The code tries to get an array of pixels out of an embeded BMP (It's 24 bit, 32x32, RGB), to use it in a texture for OpenGL, but GetDIBits() returns a zero. I've tried doing everything I can and no ...
DenisDubovik's user avatar
-1 votes
0 answers
38 views

Properly structuring QT application, two branches of a widget tree

I'm trying to build an application like Total Commander / Midnight commander in Qt6 and the architecture i did does not seem right. Widget splitting is something i can do fine, but I'm not sure how to ...
mspehar's user avatar
  • 535
-1 votes
0 answers
19 views

Tips for optimising the Conjugate Gradient Method for Large Sparse System using Eigen 3

I am quite new to Eigen and I am looking for tips on improving performance when solving large sparse systems. I am currently working on a Mac M1 machine (using CLion as IDE) and using Eigen's ...
John WK's user avatar
  • 119
-1 votes
0 answers
52 views

How to increase precision of std::stod() to e-8 or greater?

I am reading .csv and .txt files with std::ifstream and std::getline(). The files contain several thousand points. I need to read these points to a precision of at least 0.00000001 (e-8) but currently ...
QThelp's user avatar
  • 29
-2 votes
0 answers
22 views

C++ E0776 template nesting depth does not match the previous declaration of class template

I am trying to write ad n allocator, in my class I defined a template and structure and when I am trying to define it in another file I am getting this error:"Error (active) E0776 template ...
Satoshic's user avatar
-1 votes
0 answers
26 views

opengl 3d model collision detecting [closed]

I have a opengl project where I need to import 3d maze and its working fine but there is no collision and I can pass by the walls. I know I have to do math behide so i try to test on small model like ...
KA qtr's user avatar
  • 1

1
2 3 4 5
16048