Question: I have stack implementation adapted from a vector, how would I implement the move constructor and the move assignment operator .h code #ifndef STACK_H #define

I have stack implementation adapted from a vector, how would I implement the move constructor and the move assignment operator

.h code

#ifndef STACK_H
#define STACK_H
#include
#include
namespace COP4530 {
template
class Stack {
//friend functions
//invokes the print() method to print
template
friend std::ostream& operator<<(std::ostream&, const Stack&);
//returns true if the two compared stacks have the same elements, in the same order
template
friend bool operator==(const Stack& a, const Stack& b);
//returns true if every element in stack a is less than stack b
template
friend bool operator<=(const Stack& a, const Stack& b);
public:
//zero-argument constructor
Stack();
//destructor
~Stack();
//copy constructor
Stack(const Stack&);
//move constructor
Stack(Stack&&);
//copy assignment operator
Stack& operator=(Stack&);
//move assignment operator
Stack& operator=(Stack&&);
//returns true if the Stack contains no elements, and false otherwise
bool empty() const;
//delete all elements from the stack
void clear();
//adds x to the stack (copy version)
void push(const T& x);
//adds x to the stack (move version)
void push(T && x);
//removes and discards the most recently added element of the stack
void pop();
//mutator that returns a reference to the most recently added element of the stack
T& top();
//accessor that returns the most recently added element of the stack
const T& top() const;
//returns the number of elements stored in the stack
int size() const;
//prints elements of stack with delimiter
void print(std::ostream& os, char ofc = ' ') const;
private:
std::vector stack;
};
#include "stack.hpp"
}
#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!