Error: Deck::Deck names the constructor not the type

Error: Deck::Deck names the constructor not the type

我正在尝试使用以下代码重载 ++ 和 -- 运算符:

Deck::Deck& operator--(); 
{
    pop();
    Deck *this;
}      
Deck::Deck operator--(int q);
{
    pop();
    Deck *this;
}
Deck::Deck& operator++(); 
{
    push();
    return *this;
}      
Deck::Deck operator++(int q);
{
    push();
    return *this;
}

这会导致一个错误,指出 Deck::Deck 命名构造函数而不是类型。我的问题是我是否错误地实施了这段代码。这是在 deck.cpp 文件中,而在 deck.h 中是原型与甲板 class 本身的位置。任何帮助将不胜感激。

如编译器错误中所述,Deck::Deck 是 class Deck 的构造函数,因此不能用作 return 类型,相反,如果您想要 return 类型为 Deck 的对象,然后将 return 类型更改为 Deck.

此外,如果函数是 class Deck 的成员函数,那么在 class 之外定义的定义应该是这样的:

Deck Deck::operator--() { // or Deck Deck::operator--(int)
     ^^^^^^
    // body
}