Last active
August 29, 2015 14:05
-
-
Save gerner/40cd70dfe32991f78db8 to your computer and use it in GitHub Desktop.
learning about rrefs in c++11
This file contains hidden or 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 <utility> | |
#include <stdio.h> | |
#include <vector> | |
class Foo { | |
private: | |
std::vector<int> i; | |
public: | |
Foo(std::vector<int> paramI) { | |
i = paramI; | |
} | |
Foo(Foo&& foo) { | |
i = std::move(foo.i); | |
foo.i.push_back(15); | |
foo.i.push_back(26); | |
} | |
int getI() { | |
return i.size(); | |
} | |
}; | |
void bar(Foo foo) { | |
printf("foo.i (inside bar) is %d\n", foo.getI()); | |
} | |
//should print out 1 and 2 | |
int main(int argc, char **argv) { | |
std::vector<int> my_list = std::vector<int>(); | |
my_list.push_back(12); | |
Foo foo(my_list); | |
my_list.clear(); | |
bar(std::move(foo)); | |
printf("foo.i is %d\n", foo.getI()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment