Collect all kinds of c++ programming exceptions and fault solutions.


LNK2019 when trying to use FreeType 2.10.1?

I have been trying to complete the first tutorial on the FreeType website. I am using the provided code on the website and I have added the libraries and included the proper include files but I rec...


BCryptGenRandom STATUS_INVALID_HANDLE

I am trying to generate cryptographically secure numbers in Windows. I have the following code:
#ifndef w64crypt
#define w64crypt
#include <windows.h>
#include <bcrypt.h>
unsigned long


Initialization of struct pointer containing a struct pointer of same type

I am trying to understand how the initialization of a pointer to a struct object (which contains a pointer to a struct of the same type) occurs. e.g I have a struct:
struct node {
node *next;
...


Selective macro expansion using the Boost/Wave C/C++ preprocessor

For a C99 code base I am heavily depending on macros as a poor man's substitute for proper C++ templates. The most severe downside of macros for my use case is that it is hard/impossible to debug the


Default filename appears truncated in Windows IFileDialog

When using the Windows IFileDialog interface to launch File browser dialog, I face an issue if the default filename provided exceeds certain number of characters.
The filename appears truncated,


Multiple visual text cursors in QPlainTextEdit

In Sublime Text, if you hold control while clicking, you can add another cursor to the document, allowing you to type and edit in multiple places at once. I'm trying to recreate this with Qt's


Compiler error in introductory C++ example program

I'm having some difficulty reproducing an example program of Object-Oriented Programming Using C++ described in "Encapsulation and Type Extensibility."
For simplicity's sake, I've cut out most of...


why pointer assign value without address is a sign of Trojan

I'm study c++ Pointer using Notpad and Command Prompt,compiling by g++, executing the file(a.exe produce by g++). when I playing the code by delete "mypointer = &firstvalue;" The window defender po...


How to use iterators for 2d arrays in c++?

I want to use an iterator for a 2D array but I don't know how.
My purpose is to access the columns and not the rows.
I found out that to access the rows I can use this auto it=begin(arr); but I thi...


std::shared_ptr in Bison causing member error

I'm trying to make bison more memory efficient by using std::shared_ptr. I do not want to use raw pointers. I'm using a node system as the parse tree so I define YYTYPE as std::shared_ptr<Node&g...


How can I get the value of a widget the exact moment a button is clicked FLTK

The goal is to be able to get the value of a widget such as FL_Input when I click my button.
One way I could do this is by using events and classes. Such as
#include <FL/Fl.H>
#include <FL/


How to use ServerFixture from Gazebo API in ROSCPP?

I am using ROSCPP and writing my own Node within i want to load Worlds in Gazebo, simulate and delete it from gzserver. Then it should start again with another world file.
The Gazebo API offers the


Unexpected result when initializing variable in C++ using curly braces

I'm using atom to practice C++ (I'm very new). I just learned to initialize variables like the following:
#include <iostream>
using namespace std;
int main() {
int myInt {};

return ...


SFML cursor seems broken in linux

So, i have a cursor sprite:
I load this sprite with:
sf::Cursor cur;
sf::Image cur_default;
if(!cur_default.loadFromFile("assets/sprites/cursors/cursor_default.png"))
{
std::cerr <...


Is putting const before and after a function header equivalent?

While reading some code, I didn't understand the meaning of the const modifier. For example, are the following two lines equivalent?
void output() const;
const void output();


Exlude MQL4 colors from formating (e.g. C'250,250,250')

I'm using visual studio code for MQL4 files (*.mq4 - Metatrader) and using cpp associations in my settings
"files.associations": {
"*.mqh": "cpp",
"*...


C++ Won't Install in Netbeans 11.0

I'm a beginner at programming and would like to know more about C++. I installed Netbeans since it says it supports Java (which I am currently studying the basics at school) and C++ (which I want to


CGAL::Voronoi_diagram_2 rounding to integers incorrectly

I am attempting to create a Voronoi diagram from line segments with the following code.
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <...


C++ / priority_queue / Expression: invalid comparator

EDIT
I included a screenshot of the compile error with reworked code. compile error screenshot
ORIGINAL POST
I am writing a little program to practice my knowledge of priority_queue containers. I am


Is there any way to optimize c++ string += operator?

English is not good, but please understand.
string str;
string str_base = "user name = ";
string str_user_input;
string str_system_message;
...
str = str_base + str_user_input + "\n [


Huawei AREngine C++

I am trying to access to the Time Of Flight sensor, in order to use the data. In the Huawei AR Engine documentation I found the following function :
HwArPointCloud_getData(ar_session, ar_point_clou...


Is it possible to modify the templates used during creation of a C++ class by the Unreal Editor's Class Wizard?

I am starting a new project and it will require the creation of many C++ classes. In order to keep the project organized I created coded standards that will keep methods and member variables organi...


Store pair values in vector C++ from a 2d vector

I've been given a 2D vector (A). I need to store values of row and column index of that vector which contains element 0.
Here is my code-
vector<pair<int,int>>v;
for(int i=0;i<A.s...


Extract types from std::tuple for a method signature

I am looking for a way to extract the types of an std::tuple to define a method signature. Take the following (contrived) example:
template <typename RetT, typename... ArgsT>
class A
{
public...


In gRPC c++, is there a way to get notified when the peer gets disconnected?

I have implemented a gRPC server application and multiple clients can connect to it and call RPCs.
In the cases of client disconnection or client restarts, I would want to know which client got


Parsing one of two protobufs

I've some C++ code that is expecting to receive one of two protobufs. (This has occurred as an accommodation to history, not as an intentional design.)
The ParseFromString function returns false i...


C++ program reports "Process terminated with status -1073741510"

I am doing a algorithm and data structure exercise in C++ which requires to read a ten-word txt file then display them in a reserved order by using a stack without STL, class or struct. All the code


Prevent boost::asio::io_context stopping on empty poll call

This code calls the posted handle
boost::asio::io_context ioc;
boost::asio::post(ioc, []{ std::cout << "lol" << std::endl; });
ioc.poll();
whereas this doesn't:


Xbox-ATG-Samples (DirectXTK) SimpleTrianglePC causes 100% GPU usage in this circumstance

I'm tracking down a performance bottleneck. To narrow down the cause, I created a test using the SimpleTrianglePC sample from the Xbox ATG Samples repo.
I made only a few changes: I changed Draw to


Iterator vs index for quicksort implementation

Why do the following quicksort implementations have a large difference in performance? The implementation using iterators takes twice as much time as the one using indices; at both -O0 and -03


Difference in storing Unicode strings on OSX (XCode) and Windows (Visual Studio)

I've a rather complicated problem, but try to break it down to some basic stuff I can't get my head around.
At the end, I need to get a hash out of a user input string, which must be the same on Ma...


Error C2664 'HRESULT IUnknown::QueryInterface(const IID &,void **)': cannot convert argument 1 from 'const winrt::guid' to 'const IID &'

This error happens to me when I use the helper function from microsoft docs to migrate to winrt from cx. I see a similar question here, but the solution mentioned doesn't seem to work for me. The


error LNK2001: unresolved external symbol in C++ with Node-Gyp

Hello I am new to C++ and have been building an addon for one of my programs using node-gyp. However, when I try to build the addon I run into this error:
watercpp.obj : error LNK2001: unresolved


Apache Thrift timeout

I'm using apache thrift in version 0.13.0.
As soon as the time between two calls is approximately 1.5 seconds the connection will be closed.
The timeout varies from 1.3 to 1.8 seconds.
keepAlive is...


Does the future returned from std::async with the launch::deferred policy block in the destructor?

In the description of the std::async it is said that:
If the std::future obtained from std::async is not moved from or bound
to a reference, the destructor of the std::future will block at the
end...


problem with storing an image after padding

I am performing a simple masking operation with a 5x5 window. Following the accepted solution from this post Problem with Operation on Border pixels of an image (second solution), I have created a ...


Check existence of (global) function but disallow implicit conversion

Consider this simple check for whether a (global) function is defined:
template <typename T>
concept has_f = requires ( const T& t ) { Function( t ); };
// later use in MyClass<T>:
if


Is there a final, simple answer of how to detect if a function exists?

This site has 50+ post about the topic, several 'detection patterns' have had their successes through various epochs. With C++20 we should see quite some simplifications here.
So, what are the curr...


How to reverse an Adjacency list?

Let's say my adjacency list is as follows:
0 : 1
1 : 0
it's reverse should be empty because there is two arcs in the initial list:
0:
1:
or
0 : 1
1 :
becomes
0 :
1 : 0
another example:
0 :
1...


OpenGL Uniform Buffer std14 layout, normal on windows, error on macos

I wrote a simple test program to test Uniform Buffer, it runs normally on windows, but it runs wrong on macos.
on windows
show 36 quads
on macos
show 5 quads
Uniform Buffer layout in shader
struct


Why "memory_order_relaxed" treat as "memory_order_seq_cst" in my system [C++]

My Code :
std::atomic<int> x(22) , y(22);
int temp_x = -1, temp_y = -1;
void task_0(){
x.store(33, std::memory_order_relaxed);
temp_y = y.load(std::memory_order_relaxed);
}
void


How to convert TF_Tensor to opencv Mat in C++?

I am trying to port Python Tensorflow model to C++.
In process, I need to convert the TF_Tensor class to cv::Mat.
I created the output tensor as the below.
TF_Tensor** OutputValues = (TF_Tensor**)m...


GCC can not resolve method call with defaulted parameter and following parameter pack

Is GCC allowed to reject the following code due to ambiguity? To me it looks like a bug.
It compiles fine with msvc, clang and icc.
See here: https://godbolt.org/z/9fsnhx
#include <iostream>
...


how to connect two different computers, one act as server and another as client through socket programming

I have created a simple server client code using sockets in C/c++ .They run perfectly fine on same device in different terminals. How can I make them run in two different computers? Please explain in


Cannot open curl/libcurl_a_debug.lib

In my current project I'm using the library libcurl, previously installed by powershell. I'm including it using #include "curl/curl.h" and compiling works but I have a linking error that ...


Wait for thread completion without freezing the UI in MFC

I am trying to start a worker thread using AfxBeginThread and wait until it finished. But I run into the issue, that I can either update the UI (show progress) without the thread conrol or wait for...


Cannot pass shared_ptr argument to function pointer

I have a problem with the code that uses function pointer that takes shared_ptr argument.
Here is a sample code.
header.h
#include <functional>
#include <iostream>
template <class T&...


Modern Opengl Texture Pyramid

I am trying to apply an image onto my triangle; however, the result shows that the triangle display as white color. I wonder if it is possibility that my code's color is overwrite the texture.
/*He...


Crash due to mixing CRTP & interfaces?

I am experimenting with CRTP and mixing it with interfaces, and I cannot explain why this program crashes (in Clang, GCC and MSVC). In latest Clang and GCC it builds without warning with -Wall, -We...


Dynamic SQL Query with C++

Im working on a program that are accessing a SQL server.
I've established the connection, and i can get the stand i want, but only when my SQL Query is static.
I've read a post in here, where the s...


Next