Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

Explain how to build high-performance service delivery teams.

Answered: 1 week ago

Question

Understand what a service-oriented culture is.

Answered: 1 week ago