Joh*_*rad 4 c++ operator-overloading
我使用Borland 5.5编译了我的代码,没有出现错误.但它没有正确运行所以我决定使用Visual Studio 2010来调试我的程序.
Visual Studio给了我这个错误:
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\johnny\documents\visual studio 2010\projects\stack_linkedlist\stack_linkedlist\classstack.cpp 111 1 STACK_LinkedList
Run Code Online (Sandbox Code Playgroud)
它指向我的操作员过载功能.这是我的运算符重载的代码.
//operator overload
template <class S>
const Stack<S>::operator=( const Stack& s )
{
// Check for self assignment
if (&s==this)
return *this;
// Clear the current stack
while (s.theFront)
{
NodePointer p = s.theFront;
s.theFront = s.theFront->next;
delete p;
}
s.theTop = s.theFront;
// Copy all data from stack s
if (!s.isEmpty())
{
NodePointer temp = q->theFront;
while(temp != 0)
{
push(temp->data);
temp = temp->next;
}
}
return *this;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都是极好的!谢谢!
Xav*_* V. 10
没有为您的运营商定义退货类型.
const Stack<S>::operator=( const Stack& s )
Run Code Online (Sandbox Code Playgroud)
应改为:
const Stack<S>& Stack<S>::operator=( const Stack& s )
Run Code Online (Sandbox Code Playgroud)