• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ Templates and overloading operator =

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.
 
Thanks Singh...I edited the program when I posted it to this web page and must of corrected my problem in the process. I printed out my code from the form and made changes to my solution.

Programming...Got to love it 8)
 
Originally posted by: Spydermag68
If you still choose not to decide
You cannot have made a choice

I know, it's Off Topic ... but your Rush lyrics are wrong:

If you choose not to decide, you still have made a choice.



 
Quote
-------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Originally posted by: Spydermag68
If you still choose not to decide
You cannot have made a choice
--------------------------------------------------------------------------------



I know, it's Off Topic ... but your Rush lyrics are wrong:

If you choose not to decide, you still have made a choice.
-------------------------------------------------------------------------------------------

ergeorge,
You are right about the lyrics, but mine is also right. How can that be?
If you look at the published lyrics on the vinyl, cassette, and CD you will find
all have the one that i posted. When Geddy sings he uses the one that you
have posted. I am just waiting for Aug 24th.

Later,
Spydermag68


 
Back
Top