Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloading operator = error

Im trying to create a stack but im receiving errors with overloading my = operator. The stack is of type template. Heres the code

template <typename T>
T& ::stack& operator =(const stack& other)
{
    if (this == &other) return *this;

    copy(other.stack1[0], other.stack1[other.size], stack1[0]);
    return *this;
}

Any help will be appreciated. Thanks

like image 346
Nicknack Avatar asked May 10 '26 06:05

Nicknack


2 Answers

Please try the below signature

template <typename T>
stack<T>& stack<T>:: operator =(const stack<T>& other)
like image 84
user966379 Avatar answered May 11 '26 18:05

user966379


Try:

template <typename T>
stack<T>& stack<T>::operator =(const stack& other)
{
    if (this == &other) return *this;

    copy(other.stack1[0], other.stack1[other.size], stack1[0]);
    return *this;
}
like image 31
R Sahu Avatar answered May 11 '26 18:05

R Sahu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!