Code:
Stack.cpp: In copy constructor ‘Stack::Stack(const Stack&)’:
Stack.cpp:48: error: cannot convert ‘int*’ to ‘char*’ for argument ‘1’ to ‘char* strcpy(char*, const char*)’
Stack.cpp: In member function ‘Stack& Stack::operator=(const Stack&)’:
Stack.cpp:67: error: cannot convert ‘int*’ to ‘char*’ for argument ‘1’ to ‘char* strcpy(char*, const char*)’
Stack.cpp: In member function ‘void Stack::push(int)’:
Stack.cpp:167: error: cannot convert ‘int*’ to ‘char*’ for argument ‘1’ to ‘char* strcpy(char*, const char*)’
Stack.cpp:169: error: cannot convert ‘int**’ to ‘int*’ in assignment
Stack.cpp: In member function ‘void Stack::pop() const’:
Stack.cpp:189: error: decrement of data-member ‘Stack::stacksize’ in read-only structure
Code:
Stack::Stack(const Stack& s)
{
stacksize = s.stacksize;
stackcapacity = s.stackcapacity;
stackarray = new int [stackcapacity];
strcpy(stackarray, s.stackarray);
}
Stack& Stack::operator=(const Stack& rightOp)
{
if(this == &rightOp)
{
return *this;
}
delete[] stackarray;
stacksize = rightOp.stacksize;
stackcapacity = rightOp.stackcapacity;
stackarray = new int [stackcapacity];
strcpy(stackarray, rightOp.stackarray);
return *this;
}
void Stack::push(int)
{
if (stacksize = stackcapacity)
{
stackcapacity = stacksize * 2;
int* p;
p = new int[stackcapacity];
strcpy(stackarray, p);
delete stackarray;
stackarray = &p;
}
}
I think I can do it with a for loop but i dont know how..can anyone help
Last edited by a moderator: