Created
January 9, 2019 23:54
-
-
Save Grumbel/0b633d3c86d82270779d5458ed2c8785 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
class Foo | |
{ | |
public: | |
std::vector<int> m_value; | |
Foo() : m_value(10) {} | |
std::vector<int> get_value() { return std::move(m_value); } | |
std::vector<int>&& move_value() { return std::move(m_value); } | |
}; | |
int main() | |
{ | |
Foo foo; | |
std::vector<int> value = foo.get_value(); | |
Foo foo2; | |
foo2.move_value().resize(5); // Bad | |
std::vector<int> value2 = foo2.move_value(); | |
std::cout << value.size() << std::endl; | |
std::cout << value2.size() << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment