In this post, we will see how to resolve Pass a lambda which captures a unique_ptr to another function Question: I want to pass a mutable lambda which captures a unique_ptr to another function as shown in the code snippet ...
In this post, we will see how to resolve Trouble passing a function pointer to a method from main in C++ Question: I have the following set up: poster.h Then in main.cpp i have the following Every time i try ...
Question: unique_ptr<T> does not allow copy construction, instead it supports move semantics. Yet, I can return a unique_ptr<T> from a function and assign the returned value to a variable. The code above compiles and works as intended. So how is ...
Question: I’m new to move semantics in C++11 and I don’t know very well how to handle unique_ptr parameters in constructors or functions. Consider this class referencing itself: Is this how I should write functions taking unique_ptr arguments? And do ...
Question: I recently started learning about smart pointers and move semantics in C++. But I can’t figure out why this code works. I have such code: My output is: Why does row testPtr->testMethod() work? Doesn’t unique_ptr delete the pointer assigned ...
Question: I have already read various comments similar to this question here on stack overflow without finding exactly the solution to my problem. I have a Base class and Derived class an also a class that contain and also keep ...
Question: I originally had a problem creating a map of classes, with some help I realized I actually need a map<string, unique_ptr<myclass>>. To be more precise: I have a bunch of specialized classes with a common ancestor. specialized classes are ...
Question: I’m having trouble understanding the (to me intricate) mechanisms executed behind the scenes in the following code example: I’ve compiled the code with both GCC and Clang which give similar results: As is clearly visible, the address of the ...
Question: I’m having trouble understanding the (to me intricate) mechanisms executed behind the scenes in the following code example: I’ve compiled the code with both GCC and Clang which give similar results: As is clearly visible, the address of the ...
Question: I wish to express that each object of type V owns an object of type B. B is a polymorphic type, and is therefor accessed through a pointer or reference to prevent slicing (C.145). I find it natural to ...