815,029 questions
0
votes
0
answers
8
views
Why do I still get "'override' keyword is a C++11 extension [-Wc++11-extensions]" warnings even though my CMakeLists.txt sets CMAKE_CXX_STANDARD 20?
I’m working on a C++ project in CLion (macOS, Clang compiler).
My CMakeLists.txt explicitly sets the C++ standard to 20:
cmake_minimum_required(VERSION 3.16)
project(CourseWork)
set(...
Advice
2
votes
5
replies
78
views
determine cpu after c++ compilation with gcc?
Does anyone know if there is, in c++, any way to determine at runtime the cpu characteristics of the machine that compiled the code? For example, in gcc (which I'm using) the preprocessor variable ...
2
votes
0
answers
51
views
Can an exported function template invoke a module-local function using ADL?
Let's say that we have a simple main.cpp file which contains only a single call of a function bar which is defined in the module a:
import a;
int main() {
bar(1);
}
Then let's take a look at the ...
2
votes
2
answers
104
views
Declaring aliases for anonymous classes
This is an attempt to make an alias to an anonymous class:
struct {
int i = 0;
} a;
// error C7626 in MSVC
using A = decltype(a);
This produces an error in Visual Studio:
error C7626: unnamed ...
-4
votes
0
answers
99
views
Does std::string have a constructor overload for string literal or char array?
A string literal is of type const char [N], and you can pass this type to a templated function that looks like:
template <uint64_t N>
void func(const char (&arg)[N]);
On cplusplus.com, ...
0
votes
2
answers
120
views
Could we add elements in a vector with "cin >> " in C++
Could we add elements in a vector<int> n; with cin >> n[i]; in a loop in C++?
Just interested in knowing and it's my first experience using stack overflow.
0
votes
0
answers
143
views
How to implement a list with an efficient "index of" operation? [closed]
I'm interesting in possible implementation approaches for a quite special variant of a list, with the following requirements:
Efficient inverse lookup ("index of"): "give me an index ...
5
votes
1
answer
103
views
What's the difference between `extern "C" /*...*/` and `extern "C" { /*...*/ }`
Both GCC and Clang reject
extern "C" static void foo() {}
but accept
extern "C" {
static void foo() {}
}
Aren't these supposed to be equivalent?
0
votes
0
answers
47
views
OneDrive sharedWithMe returns only one item
A request from a standalone application to the sharedWithMe [1] endpoint returns only one item.
Scopes used for authorization are: files.readwrite.all group.readwrite.all sites.readwrite.all ...
0
votes
1
answer
61
views
Windows 11 raw input API bad performance compared to Windows 10
With my code which is just a regular RAW input example.... WM_INPUT, RIM_TYPEMOUSE... I'm getting on Windows 10 the full 1,000Hz of my mouse and on Windows 11 I'm getting about 128Hz.
How to fix this ...
Best practices
1
vote
7
replies
77
views
How to use in the same piece of code two different libraries with exact same declarations
I have two numerical maths libraries given by DLLs (I am under Windows) and header files. (I can't modifiy the headers and anyway there are dozens of them. I also don't have have access to a code that ...
Best practices
0
votes
7
replies
154
views
Should I use std::move when returning a local std::string as std::optional<std::string>?
My confusion is about the return statement inside readFileContents:
The function returns std::optional<std::string>, but the local variable is a std::string.
NRVO doesn’t apply here because ...
0
votes
0
answers
49
views
Is it possible to compile C++ that user types to Wasm Client side using web containers
I currently have been trying to use WebContainers + emscripten for my compilation, and i want to know if it is possible, and if not other ways to do it.
hello.js
import { WebContainer } from 'https://...
-6
votes
0
answers
73
views
Undesired Pulsating in Rendering and Cumulative Slowdown When Implementing Fixed Physics Timestep in Multithreaded Physics [closed]
INTRO
I am getting unwanted pulsing and slowing down in rendering 2d particles, which should be drawn faintly (low alpha) and leave a fading trail under the influence of gravity. Below is a ...
1
vote
0
answers
111
views
How is a non-parallelized for loop inside an OpenMP parallel section executed?
Consider the following code:
#pragma omp parallel
for (int run = 0; run < 10; run++)
{
std::vector<int> out;
#pragma omp for
for (int i = 0; i < 1'000'000; i++)
{
...
}
}
...
7
votes
1
answer
210
views
Line location as default value for an argument and template argument of a function
Suppose the following foo function has a function parameter and a template parameter, both with the same default value:
template<int Line=std::source_location::current().line()>
auto foo (int ...
-1
votes
0
answers
116
views
How to debug the C# COM class? [closed]
I have a simple C++ project which uses the CoCreateInstance to access and use some C# code (com-exposed class). The simple code looks like:
// ...
hr = CoCreateInstance(
CLSID_rclsid,
NULL, ...
11
votes
7
answers
1k
views
Is it possible to expose C++ template struct (fully specialized) to C?
I want to use circular queue with different types and lengths in a project which mainly consists of C code. I'm thinking about implementing the circular queue as a C++ template struct. How to expose ...
0
votes
4
answers
118
views
heap-use-after-free when incorrectly assigning pointers during binary tree inversion [closed]
I was attempting the binary tree inversion question on Leetcode
https://leetcode.com/problems/invert-binary-tree/
I came up with this solution
TreeNode* invertTree(TreeNode* root) {
if (root ==...
Advice
2
votes
6
replies
110
views
EOF during reading from a stream
Why does the following code throw an EOF exception during reading from the stream?
The stream state is goodbit before reading. All works as expected if I do not enable exception throwing.
https://...
-3
votes
0
answers
132
views
MFC compiles but doesn't open dialog when built with VS2022+ [closed]
I have a massive C++14, Win32 project that uses legacy MFC. So far, project compiles and works fine at Platform Toolset v142 (vs2019) and latest Windows 10 SDKs.
However, when I set the Platform ...
3
votes
2
answers
234
views
Is it ok to write `&*string.end()`?
I see many places in public repositories, where the first and last iterators of std::vector/std::string/std::string_view are converted into pointers using the combination of &* operators. In ...
Advice
0
votes
6
replies
307
views
Dynamic list of type at compile time
I'm looking for a way to store type "dynamicly" in a using (or concret implementation) that would be modifable and accessible at compile-time.
I would like something like:
struct ...
3
votes
1
answer
192
views
Why is arr[pre+1] = curr used if swapping already places the element correctly?
In this insertion sort implementation, is the line arr[pre + 1] = curr; optional?
Since we are already swapping elements inside the while-loop, won't the current element automatically reach its ...
3
votes
1
answer
159
views
compiles when returning a non-const std::vector but fails when returning a const std::vector
In the below code, I return a std::vector<A> from the get() function. If I make the std::vector<A> be a const type, the compilation fails, otherwise it passes. Can somebody explain this ...