// File: Stackt.cpp
// Stack template class implementation
#include <iostream>
usingnamespace std;
#include "Stackt.h"
// Constructor with argument, size is nelements, default is 128
template <class Type>
Stackt<Type>::Stackt(int nelements)
{
MaxSize = nelements;
stack = new Type[MaxSize];
top = -1;
}
// Copy Constructor
template <class Type>
Stackt <Type> ::Stackt(const Stackt<Type> &original)
:MaxSize(original.MaxSize), top(original.top)
{
stack = new Type[MaxSize];
for (int i = 0; i <= top; i++) stack[i] = original.stack[i];
}
//Destructor
template <class Type>
Stackt<Type>::~Stackt()
{
delete [] stack;
}
After doing some search and trying a little bit I found that the problem related to the line: S = Source;
If I remove it, the problem is gone. I also think this may be related to the copy constructor and destructor. Any help would be appreciated
Now regarding the copy assignment operator shouldn't it be something like
Since you already have a working copy constructor, you can leverage that in your copy assignment operator. Just take the parameter by value and steal it's resources in the body of the function.