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!\...
Aug 31, 2023 at 2:26pm
[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...
Aug 31, 2023 at 9:47am
[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...
Aug 30, 2023 at 3:44pm
[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
Aug 29, 2023 at 6:15pm
[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...
Aug 28, 2023 at 5:48pm
[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...
Aug 26, 2023 at 10:12pm
[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 ...
Aug 25, 2023 at 11:46pm
[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...
Aug 25, 2023 at 5:15pm
[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...
Aug 24, 2023 at 5:20pm
[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: ...
Aug 22, 2023 at 8:57am
[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...
Aug 21, 2023 at 6:05am
[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...
Aug 20, 2023 at 10:04pm
[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...
Aug 20, 2023 at 6:32am
[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 ...
Aug 20, 2023 at 6:17am
[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...
Aug 12, 2023 at 10:42pm
[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) ...
Aug 7, 2023 at 6:41am
[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...
Aug 6, 2023 at 10:22pm
[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...
Aug 6, 2023 at 6:14pm
[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) : ...
Aug 5, 2023 at 8:51pm
[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 ...
Aug 3, 2023 at 8:57am
[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.
Registered users can post in this forum.