General C++ Programming - August 2023

Uncaught error
 
Consider for VS2022: #include <iostream> int main() { int i {}; auto pi { &i }; try { delete pi; } catch (...) { std::cout << "Caught!\...
[16 replies] Last: a null pointer is fine, too 0x0000000000000000: I'm done for!... (by helios)
How to open a file that does not exist? For writing...
 
Hi, I need to open a binary files like this: fstream f; f.open(p, ios::binary | ios::in | ios::out ); but it fails because the file does not exist! I ne...
[3 replies] Last: If you want to open a file for i/o even if it does not exist, try to o... (by seeplus)
by jNc
Ubuntu/CPP emulate CTRL+V
 
Need to emulate keyboard input short cut Ctrl+V, using cpp or some wrapper/library Having something in copy buffer (just got it with Ctrl+C) Need to execut...
[1 reply] : Maybe, https://stackoverflow.com/questions/1262310/simulate-keypress-i... (by Ganado)
by jNc
get data from text file and send to text field
 
I need to make something like copy and paste Having file, get string from here, need to send (paste) it to the field where cursor now at. Please advise
[3 replies] Last: Im using Qt Editor, but I think it does not matter. It does matter. ... (by kigar64551)
What does this trick do? using unpack = int[]...
 
template<typename... T> std::string get_error_message(T&&... args) { std::ostringstream stream; using unpack = int ; static_ca...
[3 replies] Last: Thanks!! (by JUANDENT)
Why do we want perfect forwarding?
 
Hi, why should we use this code: do_print(std::forward<T>(arg)); instead of do_print(arg); I understand the first code will respec...
[3 replies] Last: Does this code demonstrates the advantage of using perfect forwarding?... (by JUANDENT)
How to require all elements of a parameter pack to satisfy a concept?
 
See this code: template<typename...T> requires is_arithmetic_v<T>... int sum_by_fold(T...v) { return (v + ... + 0); // add all elements of v starting ...
[2 replies] Last: thanks!!! (by JUANDENT)
by jNc
get inputs from OS application even if app is not active
 
Having some app, made with x11 libs, tested for ubuntu. It takes simple keyboard inputs and outputs corresponding value. It works fine if application window...
[2 replies] Last: I've googled a lot /dev/input but still not clue, how to get even smal... (by jNc)
Unable to link to a c++ dll from VB2019 (1,2)
 
I have upgraded all my projects to VS2019 and yet I still cannot get them to talk to each other between c++ and VB. I tried to add the c++ dll in the VB project...
[29 replies] Last: Hi all after, including the .def file in the youtube tutorial i manage... (by darkdave)
by StMick
Constructor Errors Between Classes
 
I'm building a LinkedList data structure with a nested Node class. The Node class within the LinkedList class looks like this: class Node { public: ...
[2 replies] Last: Perhaps what you meant to do was LinkedList<Animal *> AList; AList.a... (by helios)
how can I compare the signatures of 2 functions when one of them is a lambda and the other is a regular function?
 
Please read this code and my explanation of the question after it: auto lambda = (unique_ptr<Shape>& ps) { ps->draw(); }; template<typename...
[3 replies] Last: #include <iostream> #include <memory> #include <array> #include <stri... (by mbozzi)
by StMick
Undefined Reference to User Defined Type
 
Hello! I have built a LinkedList template class and am trying to test out its functions on a user defined type (another class called Animal in the example be...
[3 replies] Last: All the template code should go into the header file. People are gener... (by Ganado)
How can I restrict a template parameter to a certain signature
 
Hi, I have a function template acting on a collection and receiving an operation whose signature is like this: template<typename T> unique_ptr<T> nega...
[1 reply] : #include <memory> #include <ranges> #include <vector> template < typ... (by JLBorges)
How to test if a container type holds unique_ptr as its elements?
 
Hi, I need a concept that specifies whether a container type's value_type is a specialization of unique_ptr, like this: <vector<unique_ptr<T>> // for ...
[4 replies] Last: > would that concept hold true even for a std::map ? No. The value_... (by JLBorges)
Why do I get segmentation fault error?
 
I am usually pretty good at catching the root of segmentation fault error except this time. I have tested the code several times at different lengths with no su...
[6 replies] Last: @Peter87 You are right actually! Thanks! (by JamieAl)
which callable object requires std::forward when passed as an argument?
 
In which cases, when is it important to call std::forward<L>(lambda) as in the following 2 functions (given that lambda stands for some callable object) ...
[4 replies] Last: So here is a minimal example what std::forward does: #include <iostrea... (by coder777)
by frek
std::packaged_task
 
std::bind(function, argsā€¦) returns a function object that is the result of the given arguments to the given function. What does the line std::packaged_tas...
[18 replies] Last: Right. Thanks for your time and info. (by frek)
implementation of std::exchange is not clear...
 
Some code from the standard that has some tricks I do not understand: EXPORT_STD template <class _Ty, class _Other = _Ty> _CONSTEXPR20 _Ty exchange(_Ty...
[3 replies] Last: No, you're right. I misread. (by mbozzi)
How does a default move ctor deal with pointers?
 
Hi, Depending on how the compiler implements the default move ctor, this code could duplicate the pointer elements!! class Vector { Vector(int sz) : ...
[2 replies] Last: Compiler-generated move constructors copy trivial sub-objects and move... (by mbozzi)
by frek
Callback vs callable object vs function
 
I'm rather confused about terminology. I think a callback and a callable object are exactly the same thing and they're used like f in STL algorithms (or ...
[7 replies] Last: OK, thank you very much. (by frek)
August 2023 Pages: 12
  Archived months: [jul2023] [sep2023]

This is an archived page. To post a new message, go to the current page.