Spydermag68
Platinum Member
I have tested out the rest of my template that builds a dynamic stack and it works fine, but I am having trouble overloading the operator =. I have commented out the old code that worked as an "int" class
I am getting the errors in VS C++.NET:
error c2955: 'DynStack': use of clas template requires template argument list
error c2244: 'DynStack<Type>:😱perator `=": unable to match function definition to an existing
declaration
template<class Type> class DynStack
{
public:
// Constructors
DynStack(void);
DynStack ( const DynStack& copy );
// Destructors
~DynStack(void);
// Overloaded operators
// DynStack& operator=( const DynStack& rhs ); //Copy One Stack to another
DynStack& operator= ( const DynStack<Type>& rhs ); //Copy One Stack to another
// Member functions
int StackSize(void) const; // Return the size of the stack
int StackLoc(void) const; // Return the next stack location
void Push(const Type& value); // Push a number onto the stack
void Pop(Type& value); // Pop a number off of the stack
bool IsEmpty(void) const; // Is the stack empty?
void Copy( Type* to, const Type* from, int count);
private:
void Extend (int delta = 10);
Type* AllocateAndTest(int size); //#5
void Terminate (const char* string);
Type *stack; // Pointer to first element
int curr_loc; // Next available element
int total_size; // Current number of elements allocated;
};
// DynStack& DynStack:😱perator = (const DynStack& rhs)
template<class Type> DynStack<Type>& DynStack<Type>:😱perator = (const DynStack<Type>& rhs)
{
int new_size;
// Clear out the lhs stack
delete [] stack;
curr_loc = 0;
total_size = 0;
// Get new size for stack;
new_size = rhs.StackSize();
stack = AllocateAndTest(new_size); // Get new memory for stack
curr_loc = rhs.StackLoc(); // Copy top of stack location
total_size = new_size; // Copy the size of the stack
Copy(stack, rhs.stack, curr_loc); // Copy the stack
return (*this); // Return the stack
};
Thanks for your help in advance.
I am getting the errors in VS C++.NET:
error c2955: 'DynStack': use of clas template requires template argument list
error c2244: 'DynStack<Type>:😱perator `=": unable to match function definition to an existing
declaration
template<class Type> class DynStack
{
public:
// Constructors
DynStack(void);
DynStack ( const DynStack& copy );
// Destructors
~DynStack(void);
// Overloaded operators
// DynStack& operator=( const DynStack& rhs ); //Copy One Stack to another
DynStack& operator= ( const DynStack<Type>& rhs ); //Copy One Stack to another
// Member functions
int StackSize(void) const; // Return the size of the stack
int StackLoc(void) const; // Return the next stack location
void Push(const Type& value); // Push a number onto the stack
void Pop(Type& value); // Pop a number off of the stack
bool IsEmpty(void) const; // Is the stack empty?
void Copy( Type* to, const Type* from, int count);
private:
void Extend (int delta = 10);
Type* AllocateAndTest(int size); //#5
void Terminate (const char* string);
Type *stack; // Pointer to first element
int curr_loc; // Next available element
int total_size; // Current number of elements allocated;
};
// DynStack& DynStack:😱perator = (const DynStack& rhs)
template<class Type> DynStack<Type>& DynStack<Type>:😱perator = (const DynStack<Type>& rhs)
{
int new_size;
// Clear out the lhs stack
delete [] stack;
curr_loc = 0;
total_size = 0;
// Get new size for stack;
new_size = rhs.StackSize();
stack = AllocateAndTest(new_size); // Get new memory for stack
curr_loc = rhs.StackLoc(); // Copy top of stack location
total_size = new_size; // Copy the size of the stack
Copy(stack, rhs.stack, curr_loc); // Copy the stack
return (*this); // Return the stack
};
Thanks for your help in advance.