56,755 questions
0
votes
0
answers
10
views
Doxygen ignores NO_DIAGRAM
I'm documenting a C++ project with Doxygen and I want the dependency graph to only include my header file, not other libraries. I have it like this:
#ifndef CJT_ROBOT_HH
#define CJT_ROBOT_HH
#include &...
-1
votes
0
answers
16
views
Cannot open file directory 'spdlog/spdlog.h': No such file or directory
So I'm getting this fatal error from Visual Studio 2022 and I don't really undertand why it`s happening, since I clearly included the right path to the "include" folder from spdlog in the ...
0
votes
0
answers
66
views
C++ condition variable doesn't block the thread on wait_until() using the time_poin::max()?
The below code doesn't block the thread and it gets into an infinite loop and keep printing
Waiting...
Waiting...
My idea is, the thread should block on the max() time and when it's set to now(), it ...
-1
votes
1
answer
69
views
Why different threads can see different memory operation orders? [duplicate]
The following code is an example from the book C++ Concurrency in Action (2nd edition). The author mentions that threads Ta and Tb can observe different memory states:
Tc observes x == true and y == ...
2
votes
2
answers
131
views
C++ : MultiThreading : Parallelism is taking more time than Sequential
I am using threading in c++, on MAC for the first time.
Below is my code. (Motivation behind my code)
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
...
-2
votes
0
answers
77
views
Modern C++: Brace initialization not working when inside body of a class constructor? [duplicate]
So I know about uniform initialization in C++, which can be achieved by giving consistent preference to braced initialization over the (many) legacy alternatives available in the language.
Yet, I have ...
0
votes
1
answer
41
views
Why can't I declare this array of double pointers in C++
void foo(){
static const int tree1[][2] = {
{FULL,1},
{FULL,2},
{EMPTY,4},
{EMPTY,5},
{EMPTY,3}
};
static const int ...
1
vote
1
answer
27
views
Why is std::conditional reject T&?
I want to return void if template parameter is void, and return T& if template parameter is T. So, I write the next MRE code:
#include<type_traits>
template<class T>
struct Foo {
...
0
votes
0
answers
26
views
what's the __emutls_v.__tls_guard is in emutls?
I'm learning the basic implementation principle of thread_lcoal of c++11 from emutls.
I found that the __tls_init will be called when a thread_local variable was firstly accessed.
And It will called ...
-3
votes
1
answer
58
views
Assign the value to a const varable in C++ [duplicate]
Consider the following code:
class Foo
{
public:
Foo(int osId, const std::wstring &desktop)
{
m_osId = osId;
m_desktop = m_desktop;
}
private:
const int m_odId;
...
-4
votes
0
answers
70
views
Capture webcam Image and put background image and sent to other device [closed]
Could someone help me solve the problem in my code? In short, the idea is to read the webcam /dev/video0, insert a background image (jpg, png wallpaper) and send it to /dev/video2.
When running my ...
0
votes
2
answers
69
views
How to fix missing C++ symbol at link time such as ` undefined reference to `_ZTV8Settings'` [duplicate]
The linker says:
.pio/build/nano/src/canbus.cpp.o:(.literal._ZN7DalyBmsC5E6String[_ZN7DalyBmsC5E6String]+0x4): undefined reference to `_ZTV8Settings'
To me it complains a global settings referenced ...
1
vote
0
answers
40
views
Can't detect ADS-B messages via SDR
I'm making a program that detects ADS-B messages with SDR HackRF One.
The problem is program works only with test file (I found it at dump1090 repo) and if you launch detection via SDR program won't ...
-6
votes
1
answer
146
views
Segmentation fault when trying to resize a dynamic array of pointers [closed]
I've been learning some C++ for my uni courses, I've got a small but yet frustrating exercise to do. The user enters some numbers in the terminal, and it should add them to the array, when the array ...
1
vote
1
answer
80
views
C++14 constexpr function requirements on cppreference
cppreference says that, until C++14, a constexpr function must satisfy the following requirement:
the function body must be either deleted or defaulted or contain only the following:
null statements ...
2
votes
0
answers
80
views
Copying overlapping objects with auto-generated operator =
In the following program, union U has active member of type A, which is copied using auto-generated operator = into another member of type B, having A as subobject:
#include <iostream>
struct A ...
3
votes
2
answers
129
views
Implementing bitwise swap for MyString
Is the following Move operations legit, as in there is no UB.
Instead of two swaps I want to implement a one swap of the 16 Bytes of MyString.
class MyString {
std::size_t size_;
char* str_;
...
2
votes
2
answers
131
views
Why is my move assignment operator not working properly? It appears it's messing rest of couts in main as well
main.cpp
int main()
{
Mystring larry3 = "larry3"; //will call no-arg ctor not move ctor.
Mystring larry4 = larry3; // deep copy ctor is being called correctly
std::cout <<&...
0
votes
1
answer
40
views
Problems when reading binary files in C++
Here is a code to generate a binary file "input" :
#include <fstream>
int main() {
unsigned char buf[] = {
0x06, 0x00, 0x00, 0x00, 0x62, 0x6f, 0x79, 0x31, 0x00, 0x00, 0x00, ...
0
votes
1
answer
112
views
Why Does Disabling Non-Mandatory Copy Elision Result in Different Behaviors Before and After C++17
I've been experimenting with the following C++ code using different compiler flags and versions, observing differing behaviors in object construction between C++11 and C++17.
I noticed that with the -...
0
votes
1
answer
85
views
Is there a performance penalty with memory_order_relaxed?
On typical x86 and ARM systems, is there ever any performance penalty for making a variable std::atomic and only performing std::memory_order_relaxed operations? (Compared to making it a normal value ...
1
vote
1
answer
103
views
How to initialize a union containing const data members in C++11
I am having trouble initializing a union which contains const members in C++11.
In C++20 the problem is avoided by using designated initializers. Example :
union my_union
{
const void* ptr;
...
0
votes
2
answers
60
views
`std::sprintf` or `std::snprintf` with parameter pack without additional call and tmp buffer
Is there a way to get ride of the tmp and the second call to std::snprintf in Print? Can I do the same with just one std::snprintf call?
// arm-none-eabi-g++ -std=c++14 -O3 -Wall -fno-rtti -fno-...
2
votes
1
answer
140
views
How to define function argument as an other function argument
For example how to impalement Wrapper::call_to_func
that argument list call_to_func should be as func
class A
{
void func(int, char, double);
};
template<class T>
class Wrapper
{
public:
...
-3
votes
1
answer
93
views
How can shared_ptr using -> and . operator with same variable name?
i stuck with a confusion in example below i have declared a shared ptr 'u'
i am using u->data as well as u.use_count()
Since 'u' holds a pointer then how can we use dot operator to call use_count , ...
0
votes
0
answers
56
views
How to disable exceptions in boost recursive_directory_iterator?
I am using Ubuntu 20.04, c++ 11 and Boost Filesystem 1.71. Just trying to traverse directory that contains some elements not accessible by current user in c++ but exception always occurs when such ...
1
vote
0
answers
73
views
why the C++ app crashes when running again updated shared library
I create a dummy c++ app:
---->libmars.so:
---->mars.h:
#ifndef mars_h__
#define mars_h__
class AAA {
public:
AAA();
};
#endif // mars_h__`
--->main.cpp
#include <stdio.h>
#...
0
votes
0
answers
27
views
How to delete flatbuffers received from ZeroMQ
I'm looking for an example in C++ 11 to delete flatbuffers received by ZeroMQ.
I have two applications: Publisher and Subscriber.
I know that on the Publisher (sender) side, that the ...
0
votes
1
answer
42
views
How to send a pointer of a method of an object into a function? (Solved)
I'm trying to create a notebook program
cpp file:
#include <string>
#include "Menu.h"
class Notebook
{
std::vector<std::string> m_notes;
public:
void addNote()
{
...
2
votes
1
answer
72
views
Template argument deduction in perfect forwarding [duplicate]
I'm learning perfect forwarding, and run the example code(listed bellow)
template<typename T>
void show_type(T t){
std::cout << typeid(t).name() << std::endl;
}
template<...
1
vote
1
answer
111
views
Can std::chrono's time_point silently overflow?
#include <iostream>
#include <chrono>
int main()
{
constexpr std::chrono::duration<float> kLastWarningMsgDuration{ 10 };
// default time point (zero)
std::chrono::...
1
vote
0
answers
33
views
C++ Code doesn't give any output and stuck
I am making a lexer & parser for a 8 bit cpu, my lexer is working fine but when I added AST class for parse, this problem started. Whats the problem and how to solve it
The code takes a string ...
0
votes
0
answers
42
views
How do I recognize duplicate braces and output the value? (StringDecoder(about stack))
string decodeString(const string& encoded) {
string decoded;
int i = 0;
while (i < encoded.length()) {
if (isHexDigit(encoded[i])) {
int repeatCount = stoi(...
0
votes
1
answer
44
views
Why does copy_if implementation not take unary_predicate as const reference parameter
template<class InputIt, class OutputIt, class UnaryPred>
OutputIt copy_if(InputIt first, InputIt last,
OutputIt d_first, UnaryPred pred)
{
for (; first != last; ++first)
...
1
vote
2
answers
114
views
Wrong result in Eigen when returning a expression from within a lambda
I'm trying to use the body of this function in a lambda:
Vector3d fun(Vector3d const& point) {
Vector3d const b{ 0., 0., 30. };
return b + point.normalized();
}
but when the result is not ...
0
votes
1
answer
56
views
How to initialize an array of structs containing union in C++11?
My question is tightly coupled with my another question. I have been struggling with initialization of an array containing struct members with union.
Let's say I have following declarations in C++11
...
3
votes
1
answer
137
views
Unclear template resolution
I was going through the exercises in this post https://www.slamecka.cz/posts/2021-03-17-cpp-metaprogramming-exercises-1/
First of all, I want to say huge thanks to the author. The problems were quite ...
2
votes
2
answers
114
views
C++ class member's specialization with nontype arguments
I need to define a class with nontype template parameters and specialize one of its function member's. The code below is a reasonable simplification of what I need to do (we can assume this is c++11 ...
0
votes
1
answer
99
views
C++ smart pointers to FFmpeg objects
Can I create and use C++ smart pointers for different pointer types from FFmpeg?
"AVCodecContext *" which is used only as a pointer in all functions except deallocation.
Alloc:
...
0
votes
1
answer
90
views
Is this a standard conforming way for selective constructor "inheritance"?
In trying to inherit constructors selectively (ie just some of them) I found a way that seem to work with GCC:
#include <string>
#include <iostream>
struct B
{
B()
{
...
0
votes
2
answers
42
views
Issue calling a variadic template constructor
The following code doesn't work, it fails because it cannot find a constructor with a <int, bool> signature.
I know can't specify explicitely the template parameters in the case of a constructor....
2
votes
3
answers
198
views
Why can't -2147483648 represented in hex literal?
Based on C++ documentation the size to hold hex literal grows from int -> unsigned int -> long -> unsigned long -> long long -> unsigned long long.
But I wonder how to specify hex ...
1
vote
0
answers
34
views
"auto" keyword not working properly in Eclipse during live code analysis?
I'm using Eclipse with the MinGW compiler. I have the following code snippet, which results in the error "Method 'push_back' could not be resolved", but surprisingly the code works. More ...
3
votes
1
answer
83
views
C++11 designated initializers for Union
Why do designated initializers for union work in C++11?
According to doc, it is C++20 feature
https://en.cppreference.com/w/cpp/language/aggregate_initialization
union u { int a; const char* b; };
// ...
1
vote
1
answer
29
views
Efficiently returning local object allocated with external memory resource in boost::json
As part of a larger C++11 application, I have a function which creates a Boost JSON object and then returns it. One of the parameters to this function is a Boost JSON storage_ptr to an external ...
2
votes
0
answers
62
views
unique dependent type for decltype(dependent-expression) in C++
I have a doubt about what is the effect for decltype(dependent-expression) to determine a "unique dependent type".
This other discussion stackoverflow_link deals with this topic but it just ...
2
votes
1
answer
98
views
Using size_type as iterator offset - difference between GCC/Clang and MSVC
I'm trying to use size_type as offset to string iterator in std::copy() algorithm. When size_type is std::string::npos, GCC/Clang doesn't throw any exception but MSCV throws cannot seek string ...
1
vote
1
answer
27
views
Got "expected type specifier" error while instantiating my property
My goal is to create nullable value which takes both a default value function and a key to retrieve a potential customization of the value from the flash storage.
But trying to instantiate it as a ...
1
vote
1
answer
146
views
Does std::unique_ptr support fancy pointers?
Can std::unique_ptr manage pointers only, or fancy pointers (pointer-like types) too?
I assume "fancy pointers too", because for resources like files/sockets, fancy pointers can be a great ...
1
vote
1
answer
35
views
What is the return value of `wait_until` in case of triggered or spurious wakeup, when timeout was reached?
I have a question for the "first" version of std::condition_variable::wait_until, that is, the one without the condition predicate parameter, which should return std::cv_status value.
The CV ...