链接列表的串联

我有一个连接2个赌注的功能:

template<class Type>
Stack<Type> Stack<Type>::concatenate(Stack<Type> stack2) {
    Node* temp = vertex;
    for (int i = 0; i < size - 1; i++) { temp = temp->prev; } //Going to the end of linked list
    temp->prev = stack2.vertex;
    size += stack2.get_size();
    return *this;
}

Maybe more correct would be to call it a merge function, as stack2 becomes out-of-use, because we "concatenate" simply by assigning an address of stack2 to the end of stack (no copying). But somehow I wanted the function to return result (so list3 = list.concatenate(list2) makes list3 a copy of list1), this is why it return *this;, and I created a copy constructor for this purpose:

template<class Type>
Stack<Type>::Stack(const Stack<Type>& other) {
    for(int i = other.get_size() - 1; i >= 0; i--) { (*this).push_back(other[i]); }
    size = other.size;
}

The most interesting is that after list3 = list.concatenate(list2) we get different list and list3. list3 is as it's supposed to be, while list causes EXC_BAD_ACCESS when I try to print its elements, which doesn't make sense at all, as list3 is simply a copy of list, and if the problem was with copy constructor, it would be vice-versa.

The Stack class:

template<class Type>
class Stack {
private:
    struct Node;
    Node* vertex;
    int size;
public:
    Stack()
        : vertex(nullptr), size(0)
    { }
    ~Stack() {
        this->clear();
    }
    Stack(const Stack<Type>& other);
    const int& get_size() const { return size; }
    void push_back(const Type& n_value);
    void pop_back();
    void clear();
    Stack<Type> concatenate(Stack<Type> stack2);
    Type&& operator[](int index);
    const Type&& operator[](int index) const;
};

template<class Type>
struct Stack<Type>::Node {
Type value;
Node* prev;
Node()
    : prev(nullptr)
{ }
Node(Type n_value)
    : value(n_value), prev(nullptr)
{ }
};

template<class Type>
Stack<Type>::Stack(const Stack<Type>& other) {
    for(int i = 0; i < other.get_size(); i++) { (*this).push_back(other[i]); }
    size = other.size;
}

template<class Type>
void Stack<Type>::push_back(const Type& n_value) {
    Node* old_vertex = vertex;
    vertex = new Node(n_value);
    vertex->prev = old_vertex;
    size++;
}

template<class Type>
void Stack<Type>::pop_back() {
    Node* new_vertex = vertex->prev;
    delete vertex;
    vertex = new_vertex;
    size--;
}

template<class Type>
void Stack<Type>::clear() {
    for (int i = 0; i < size; i++) { this->pop_back(); }
}

template<class Type>
Stack<Type> Stack<Type>::concatenate(Stack<Type> stack2) {
    Node* temp = vertex;
    for (int i = 0; i < size - 1; i++) { temp = temp->prev; }
    temp->prev = stack2.vertex;
    size += stack2.get_size();
    return *this;
}

template<class Type>
Type&& Stack<Type>::operator[](int index) {
    if (index >= size || index < 0) { throw std::out_of_range("Index of Stack is out of range."); }
    else {
        Node* temp = vertex;
        for (int i = 0; i < index; i++) { temp = temp->prev; }
        return std::forward<Type>(temp->value);
    }
}

template<class Type>
const Type&& Stack<Type>::operator[](int index) const {
    if (index >= size || index < 0) { throw std::out_of_range("Index of Stack is out of range."); }
    else {
        Node* temp = vertex;
        for (int i = 0; i < index; i++) { temp = temp->prev; }
        return std::forward<Type>(temp->value);
    }
}

编码:

int main() {
    Stack<int> list;
    for (int i = 1; i < 5; i++) { list.push_back(i); }
    for (int i = 0; i < list.get_size(); i++) std::cout << list[i] << '\n';
    std::cout<<"------------------\n\n";
    Stack<int> list2;
    for (int i = 10; i < 15; i++) { list2.push_back(i); }
    for (int i = 0; i < list2.get_size(); i++) std::cout << list2[i] << '\n';
    std::cout << "1-------------------\n\n";
    Stack<int> list3 = list.concatenate(list2);
    std::cout << list3.get_size() << '\n';
    std::cout << list.get_size() << '\n';
    std::cout << "2-------------------\n\n";
    for (int i = 0; i < list3.get_size(); i++) std::cout << list3[i] << '\n';
    std::cout << "3-------------------\n\n";
    for (int i = 0; i < list.get_size(); i++) std::cout << list[i] << '\n';
    std::cout << "4-------------------\n\n";
    return 0;
}

输出:

4
3
2
1
------------------

14
13
12
11
10
1-------------------

9
9
2-------------------

4
3
2
1
14
13
12
11
10
3-------------------

4
3
2
1
268871820
(lldb) 

Error: Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

编辑:更正了副本构造函数。