Vid*_*dak 2 c++ operator-overloading prefix-operator postfix-operator operator-keyword
当使用运算符重载前缀和后缀增量时,我从编译器收到错误:
"Fajl Fajl :: operator ++(int)':已定义或声明的成员函数"
以下是operator ++的标题:
Fajl& operator ++ (); // prefix
Fajl& operator -- (); // prefix
Fajl operator ++ (int); // postfix
Fajl operator ++ (int); // postfix
Run Code Online (Sandbox Code Playgroud)
而我的实施:
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;
}
Run Code Online (Sandbox Code Playgroud)
"Fajl"是这个类,而"poz"是我正在增加的论点.我究竟做错了什么?
Fajl operator ++ (int); // postfix
Fajl operator ++ (int); // postfix
^^
should be --
Run Code Online (Sandbox Code Playgroud)