codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <vector> #include <string> #include <iostream> using namespace std; class my_string : public string { typedef string super; public: my_string(const char *s) : super(s) { cout << "Constructed my_string" << endl; } my_string(const my_string &rhs) : super(rhs) { cout << "Copied my_string" << endl; } my_string(my_string &&rhs) : super(rhs) { cout << "Moved my_string" << endl; } my_string &operator=(const my_string &rhs) { super::operator=(rhs); cout << "Assigned my_string" << endl; return *this; } }; class my_vector : public vector<my_string> { typedef vector<my_string> super; public: my_vector() : super() { cout << "Constructed my_vector" << endl; } my_vector(const my_vector &rhs) : super(rhs) { cout << "Copied my_vector" << endl; } my_vector(my_vector &&rhs) : super(rhs) { cout << "Moved my_vector" << endl; } }; my_vector get_a_vector() { my_vector result; result.push_back(my_string("First")); return result; } int main(void) { for (my_string str : get_a_vector()) { } return 0; }
Private
[
?
]
Run code
Submit