Questions tagged [c++11]

C++11 is the version of C++ after C++03. This tag should be used (along with the [C++] tag) for questions about C++ features specific to C++11.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
100 views

Partially deallocating structs/classes in C++

Is there a way to partially deallocate structs/classes in C++? I was trying to build some sort of a new pointer in C++ that point to RefCount template<typename T> struct RefCount { unsigned ...
Ak2399's user avatar
  • 827
0 votes
0 answers
31 views

gtsam error report : Assertion `SizeAtCompileTime == Dynamic || SizeAtCompileTime == dim' failed

I wrote a custom unary factor using gtsam. There is no problem compiling, but an error occurs when running. However, the error reported is strange. The line of code reporting the error is as follows: ...
zhibo zhao's user avatar
0 votes
0 answers
65 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,548
-2 votes
1 answer
51 views

What is the correct way to pass std::bind<> to constructor of another class? [closed]

I checked the following links but I couldn't resolve my issue: https://en.cppreference.com/w/cpp/utility/functional/function How to set a callback by binding a class method in C++ I have 3 classes: ...
Makketronix's user avatar
  • 1,396
0 votes
0 answers
33 views

How to translate a np.array.view() operation to c++ function

How can I perform this operation in c++ : y = y.view(dtype=int64) * (2**-18), where y is a numpy array where each element holds 16 uint8_t values (128-bits in total). This is my input y : [0 0 4 0 0 0 ...
akshay malige's user avatar
1 vote
1 answer
71 views

What are the rules for uniform initialization of a union [duplicate]

If i compile the following code ... int main() { union U { struct { int i, j; } s; long long x, y; int z; }; U li { 1 }; } ... either x or y becomes ...
Edison von Myosotis's user avatar
0 votes
1 answer
87 views

C++11 Memory model: the compiler is restricted to don't introduce new data races

Watching a CppCon talk by Michel Wong on 2015 (called C++1/14/17 atomics and memory model... about minute 33:00), he said two sentences that I didn't understand: No compiler transformation is allowed ...
ABu's user avatar
  • 10.7k
-1 votes
0 answers
36 views

Lack of LLVM support [closed]

LLVM is such a powerful tool, it is very well established and has a large community. As an undergraduate student I had project and needed to use the LLVM API. Words cannot describe how traumatised I ...
Jonas's user avatar
  • 1
0 votes
0 answers
18 views

Filter sober in c++ don't pass test

I am working on implementing the Sobel filter for image processing in C++. However, I am encountering unexpected results and failing test cases. I have reviewed the code multiple times, but I cannot ...
ste005Code's user avatar
0 votes
1 answer
61 views

Class with vector of another class doesn't like to change its values [duplicate]

I have a class called intClass that contains a private vector of ints and functions to modify its contents. I have another class called intClassClass that contains a private vector of intClasses and ...
scutoid's user avatar
0 votes
2 answers
86 views

With C++11, how can I generate a warning message in a manner that works in gcc, clang, and MSVC?

When compiling C++11 using clang or gcc, I can generate a warning message at compilation time using: #warning My message here This doesn't work on Windows when I use MSVC, though. How can I ...
Bri Bri's user avatar
  • 2,087
0 votes
1 answer
77 views

Template specialisation or function overload

I created a two classes - one can be converted to another by the conversion operator: struct MyClass{}; struct MyClass2{ operator MyClass() const { return MyClass{}; } }; and a specialised ...
Patryk's user avatar
  • 138
0 votes
0 answers
20 views

Debugging issue - Calculator08buggy.cpp from Programming principles and practice of Bjarne Stroustrup

As part of the drill I need to find 3 errors in the code, but I was just able to solve one were I just needed to declare a construct for Token(name, s). I need clues in what other things could be ...
Diushen's user avatar
-3 votes
0 answers
33 views

Why is a reference to a static variable unresolved in the linker? [duplicate]

Win11 MSVC 2022 (64-bit) - Version 17.8.0 C++14 I have a simple program, below. I can not reference the static variables within a function in the source code (*.cpp file), but I can reference object ...
lostbits's user avatar
  • 932
0 votes
0 answers
69 views

Why do I get the error "Expression must have class type but it has type Calculator(*)()" when I create an object?

Context: I am learning C++ and came across the concept of delegating constructors and also member initializer lists. I was creating a very basic calculator class and I came across the error message &...
Mole_Boy's user avatar
-1 votes
1 answer
99 views

Forward Declaration (PIMPL) for External Libraries also used in Method Declarations?

I have looked at a significant number of posts regarding forward declarations/PIMPL, but haven't quite managed to get it to work with the external libraries I'm using. I want to create a shared ...
RPH's user avatar
  • 55
-2 votes
0 answers
42 views

removing duplicates element in an array

class Solution { public: int removeDuplicates(vector<int>& nums) { vector<int>ans; int n=nums.size(); sort(nums.begin(),nums.end()); ...
Amitabh Shanker's user avatar
0 votes
0 answers
28 views

Handling of error in streambuf::underflow? [duplicate]

I am trying to make sense of the code posted by @dietmar-kühl at: https://stackoverflow.com/a/14086442/136285 I do not understand how I am supposed to handle error from within underflow. I have ...
malat's user avatar
  • 12.1k
0 votes
1 answer
26 views

could not convert 'str' from 'const QStringBuilder<QString,char[5]>' to 'std::string{ask std::basic_string<char>}'

could not convert 'str' from 'const QStringBuilder<QString,char[5]>' to 'std::string{ask std::basic_string}' code: template<class T> inline std::string toString(const T&str) { return ...
杨建国's user avatar
0 votes
0 answers
25 views

Nested use of C++ std::async to create threads, which can delay the exception when there is insufficient resources

I am trying to simulate the exception behavior when the number of threads exceeds the linux limit. I found that when I continuously use std::async(std::launch::async, &func) in a thread, without ...
Consen's user avatar
  • 1
0 votes
1 answer
93 views

List-initialization of vector of pairs

Note: Please don't close the question just because the root cause was due to comma operator. The value of the question was to let the community understand the failure of: std::vector<std::pair<...
cpp's user avatar
  • 291
0 votes
1 answer
49 views

How can I inherit a magic static singleton?

I would like to inherit from a magic static singleton in a derived: #include <iostream> int main(); class SingletonBase{ protected: int i=0; SingletonBase(int){} // friend int ...
GRamon's user avatar
  • 77
-1 votes
0 answers
20 views

Live suggestions in a dictionary c++

I am doing a course project where I have to build a dictionary. I have already made the dictionary using the trie. The problem now is that I have to show live suggestions as the user types the word ...
SAAD ULLAH's user avatar
-3 votes
1 answer
202 views

How to prevent copy elision when implementing custom array functionality?

I'm writing a class CValue in C++, which is supposed to be an analog of values in JavaScript. CValue object can be almost every type, depending on initialization/assignment: primitive value (bool, int,...
asethone's user avatar
1 vote
0 answers
78 views

Is there any potential problem when casting an int to enum when the int is greater than the number of possible values? [duplicate]

Is there any potential problem that I should be aware of when casting an int to enum when the int is greater than the number of possible values, say Here is the code snippet, which seems work well:) : ...
John's user avatar
  • 3,085
-2 votes
1 answer
57 views

How can an object find that is rvalue reference(unnamed value) in C++? [duplicate]

I have a class named Matrix. I want overload operator ! that return transpose of matrix. When the main matrix is a unnamed object I prefer to use it's allocated memory to construct transpose matrix, ...
H.Ayatollahi's user avatar
-1 votes
1 answer
61 views

template specialization of unique_ptr generating member function

I am trying to make comm class with template variable. My colleague ask me to use std::unique_ptr for memory management. But I think I failed to implement polymorphysm. I wrote code as the following. ...
jaewook kim's user avatar
1 vote
1 answer
41 views

Passing processor-function in library for ESP AsyncWebServerRequest

I'm trying to include the ESPAsyncWebServer lib in an own C++ class/library. I'm struggling to pass the processor function when starting a server. Same problem was discussed here: Calling member ...
fabibo89's user avatar
-1 votes
0 answers
44 views

RunTime Error - member access within null pointer of type 'ListNode'

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ...
Shrey Kumar's user avatar
1 vote
1 answer
52 views

The implementation of add_rvalue_reference

Why does the result become an rvalue reference when deducing from a function returning type directly for a function type, while the implementation in bool_constant yields the correct type? #include &...
Jonny0201's user avatar
  • 463
3 votes
2 answers
173 views

How to Improve XORing of large uint64 arrays?

I want to xor large shifted arrays, following is portable version of that function for easy of explanation. How I can improve this computation? I have tried using AVX2 but didnt see much improvement. ...
CryptoKitty's user avatar
0 votes
1 answer
122 views

How to iterate over ranges of a std::vector

I have a question on what's the best way to iterate over slices/ranges of a vector with C++11 or C++14. Let's say we have a std::vector that holds a bunch of values: std::vector<int> v = {0,1,2,...
RAM's user avatar
  • 2,518
2 votes
1 answer
150 views

Fix QObject: Cannot create children for a parent that is in a different thread

I have noticed this message in my Application Output in Qt Creator: QObject: Cannot create children for a parent that is in a different thread. (Parent is QUdpSocket(0x557d126bb830), parent's thread ...
Veljko's user avatar
  • 97
-2 votes
0 answers
36 views

Access and open Windows user details page

I need to open the windows user details page and read the information. But access to this page is limited. I want this window to pop up without an intermediary when I click on a button in qt During my ...
samaneh's user avatar
0 votes
1 answer
29 views

Code runs slower on Intel XEON than Intel i7?

I have some code in which the following function is responsible for 95% of computation void processServerData(uint32_t partIndex, uint32_t dataOffset, uint64_t *outputData, uint32_t dataSize, uint32_t ...
CryptoKitty's user avatar
2 votes
1 answer
65 views

What part of static initialization is thread safe?

If I have a global value getter like this bool get_global_bool() { static const bool b{get_the_value()}; return b; } I know that b will be initialized in a thread safe way but will I also be ...
cppguy's user avatar
  • 3,653
1 vote
0 answers
34 views

C++ Phase 1 Translation Set of Source File Characters: Before vs. Post C++11, before C++23

cppreference's page on phases of translation , for Phase 1 of translation (prior to C++23), has a note in its Step 2. that: The set of source file characters accepted is implementation-defined (since ...
mishar's user avatar
  • 401
1 vote
1 answer
66 views

Internal state of std::discrete_distribution and random numbers quality

I am iteratively generating random numbers via std::discrete_distribution. Does the quality of random numbers degrade if after each iteration I reset the internal state of the distribution (which is ...
user2052436's user avatar
  • 4,441
1 vote
0 answers
44 views

Moving third party library from header file

I have the following code snippet: #include <nats/nats.h> class MyClass { public: // some functions here private: template<typename T, void (*DestroyFn)(T*)> decltype(DestroyFn) ...
David Hovsepyan's user avatar
0 votes
1 answer
118 views

How long does it take for one thread to notify another thread?

I want to measure how long it takes for a condition variable to notify another waiting thread. I wrote this example to try to capture the time difference: bool ready{false}; mutex m; ...
user3100212's user avatar
2 votes
1 answer
70 views

Two Dimensional Array init in C++11

I'm trying to get full understandig of C++ arrays init. Here is the code snippet: int main() { const int n= 20; int m; m = n+10; int (*a)[m] = new int [n][m]; //1 int *w = new int [...
Ivan's user avatar
  • 23
0 votes
3 answers
192 views

Convert enum values to strings

I have the following code snippet: enum class Code : uint8_t { A = 0, B = 1, C = 2 }; How can I add a conversion operator (or something similar if possible) to the enum such that when I ...
David Hovsepyan's user avatar
-2 votes
1 answer
27 views

C++ Vector Declaration Syntax

Confused why vector declaration syntax is different than any other data structure. For example an Array. vector<int> myvector Whereas an array can be declared as such int arr[] = {1, 2}
Harry's user avatar
  • 281
-1 votes
1 answer
34 views

friend declaration declares a non-template function, undefined reference

I have such template class, which includes a friend method: template<class T1, class T2, int n> class Graph final { private: std::array<T1, n> vertex; std::array<std::array<...
MeYokYang's user avatar
0 votes
0 answers
36 views

Method parameter copied (not moved) [duplicate]

I have the following code: // header void Method1(const bool& b, std::vector<int>&& v); bool Method2(); bool CMyClass::Method1() { std::vector<int> v{ 1, 2, 3 }; ...
Flaviu_'s user avatar
  • 1,303
0 votes
0 answers
31 views

C++ "atomic_compare_exchange_strong" apply to non-atomic variable

std::shared_ptr<int> node; int *expect = new int(1); int *desire = new int(2); atomic_compare_exchange_strong(&node, &expect, desire) What makes this code run as I image? the "node&...
besnnad's user avatar
1 vote
1 answer
103 views

How can hours, minutes, and seconds be extracted from a time_point in milliseconds?

How can I extract hours, minutes, and seconds from a given std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>? My code in below does not return the hour correctly. It ...
afp_2008's user avatar
  • 2,061
1 vote
0 answers
53 views

Calling the std::future destructor when an exception is thrown

There is this code: #include <chrono> #include <future> #include <iostream> using namespace std::chrono_literals; int main() { try { std::atomic<bool> ...
Andrey Epifantsev's user avatar
0 votes
0 answers
45 views

How to suppress warning -Wignored-attributes using __m128 on templates?

I've this basic code: #include <iostream> #include <emmintrin.h> template <typename T> struct SRCDecimator { SRCDecimator() { } }; int main() { SRCDecimator<__m128&...
markzzz's user avatar
  • 47.7k
0 votes
0 answers
17 views

undefined reference to `CommonAPI::SomeIP::Message::createErrorResponseMessage

The project set up was working fine in another system with same set of libraries and source code. I have checked if all the dependent libraries required are available in /usr/bin. The libraries use ...
Megha Koujageri's user avatar

1
2 3 4 5
1132