From 40ba052bc8d65b50a0389461e4f3e75f60c5b135 Mon Sep 17 00:00:00 2001 From: wrazik Date: Wed, 22 Apr 2020 14:24:25 +0200 Subject: [PATCH] Fix C++ slide --- workshop/04-ownership/slides.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/workshop/04-ownership/slides.md b/workshop/04-ownership/slides.md index 67a8f10..b1cbc47 100644 --- a/workshop/04-ownership/slides.md +++ b/workshop/04-ownership/slides.md @@ -50,17 +50,18 @@ In C++ we have move semantics, in Rust there is semantical move - moved object i ### Move in C++ ```cpp -float area(circle: Circle) { - return std::numbers::pi_v * circle.radius * circle.radius; - // `circle` destructor is called +float area(Circle&& circle) { + Circle local = std::move(circle); + return std::numbers::pi_v * local.radius * local.radius; + // `local` destructor is called } int main() { auto circle = Circle(2.0); - // `circle` moved to `area` - move constructor is called, which leaves - // old `circle` in undefined destructible state + // `circle` moved to `area` - move constructor may be called, which leaves + // old `circle` in after-move state std::cout << "Circle area: " << area(std::move(circle)) << '\n'; - // Circle is a valid but undefined object here - basically semantic UB. + // Circle may be a valid but unspecified object here - basically semantic UB. std::cout << "Circle area: " << area(std::move(circle)) << '\n'; // `circle` destructor is called }