[ create a new paste ] login | about

Link: http://codepad.org/rcmceFY4    [ raw code | output | fork ]

C++, pasted on Oct 31:
#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;
}


Output:
1
2
Line 19: error: expected ',' or '...' before '&&' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: