c++ - 后缀前缀运算符重载错误 C++

标签 c++ operator-overloading operator-keyword postfix-operator prefix-operator

当对前缀和后缀增量使用运算符重载时,编译器出现错误:

"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/

相关文章:

c++ - 在几层继承上重载解析?

c++ - 我相信短语 "not previously declared to have external linkage"在 N4140 的§3.5/3 项目符号点 (3.2) 中是多余的

c++ - 使用没有引用参数名称的类重载复制赋值运算符

c++ - C++ 中的命名空间类模板继承

c++ - 链表 |重载 + 运算符 | C++

C# 前自增和后自增运算符重载如何操作?

c++ - 三元运算符的奇怪隐式转换

c++ - RcppArmadillo 和 R 3.1.3 以及 Mac Yosemite 的编译错误

c++ - 如何告诉 C++ 根据索引指示符放弃 vector 中的某些元素

c++ - 重载运算符<<用于嵌套类模板