当对前缀和后缀增量使用运算符重载时,编译器出现错误:
"Fajl Fajl::operator ++(int)' : member function already defined or declared"
这是我的运算符++ 的标题:
Fajl& operator ++ (); // prefix
Fajl& operator -- (); // prefix
Fajl operator ++ (int); // postfix
Fajl operator ++ (int); // postfix
还有我的实现:
Fajl& Fajl::operator ++ () // prefix
{
++(*poz);
return *this;
}
Fajl& Fajl::operator -- () // prefix
{
--(*poz);
return *this;
}
Fajl Fajl::operator ++ (int dummy) // postfix
{
Fajl temp(*this);
++(*this);
return temp;
}
Fajl Fajl::operator -- (int dummy) // postfix
{
Fajl temp(*this);
--(*this);
return temp;
}
“Fajl”是类,“poz”是我递增的参数。我做错了什么?
最佳答案
Fajl operator ++ (int); // postfix
Fajl operator ++ (int); // postfix
^^
should be --
关于c++ - 后缀前缀运算符重载错误 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8254838/