Category : destructor

I stumbled across a behaviour of std::make_pair that I do not understand. Given the following code #include <iostream> using namespace std; #include <memory> #include <utility> class TestClass { public: TestClass(const std::string& str) : str{std::make_unique<const std::string>(str)} {}; // ~TestClass() = default; // (1) private: // std::unique_ptr<const std::string> str{}; // (2) // const std::unique_ptr<const std::string> str{}; // ..

Read more

I am struggeling with a memory error when calling the destructor of the folowing class: class Point { private: int dimensions; double *values; public: Point(const int dim); Point(const Point &that); ~Point(); Point &operator=(const Point &that); double operator[](int i) const; int dim() const; void print(); }; The constructor is implemented as follows Point::Point(const int dim) : ..

Read more

Look at this oversimplified example: std::coroutine_handle<> logger; const char* next_msg = nullptr; void log(const char* msg) { next_msg = msg; if (logger) logger.resume(); } struct wait_msg { bool await_ready() { return next_msg != nullptr; } void await_suspend(std::coroutine_handle<> h) { logger = h; } auto await_resume() { const char* msg = next_msg; next_msg = nullptr; return ..

Read more

Look at this simplified example: std::coroutine_handle<> logger; const char* next_msg = nullptr; void log(const char* msg) { next_msg = msg; if (logger) logger.resume(); } struct wait_msg { bool await_ready() { return next_msg != nullptr; } void await_suspend(std::coroutine_handle<> h) { logger = h; } auto await_resume() { const char* msg = next_msg; next_msg = nullptr; return ..

Read more