相关疑难解决方法(0)

GCC无法区分operator ++()和operator ++(int)

template <typename CRTP>
struct Pre {
    CRTP & operator++();
};

template <typename CRTP>
struct Post {
    CRTP operator++(int);
};

struct Derived
    : Pre<Derived>
    , Post<Derived>
{};

int main() {
    Derived d;
    d++;
    ++d;
}
Run Code Online (Sandbox Code Playgroud)

我从GCC得到这些错误:

<source>: In function 'int main()':
<source>:18:10: error: request for member 'operator++' is ambiguous
        d++;
        ^~
<source>:8:14: note: candidates are: CRTP Post<CRTP>::operator++(int) [with CRTP = Derived]
        CRTP operator++(int);
            ^~~~~~~~
<source>:3:16: note:                 CRTP& Pre<CRTP>::operator++() [with CRTP = Derived]
        CRTP & operator++();
                ^~~~~~~~
<source>:19:11: error: request for member …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading multiple-inheritance ambiguous

60
推荐指数
1
解决办法
3528
查看次数

死亡钻石和范围解析算子(c ++)

我有这个代码(钻石问题):

#include <iostream>
using namespace std;

struct Top
{
    void print() { cout << "Top::print()" << endl; }
};

struct Right : Top 
{
    void print() { cout << "Right::print()" << endl; }
};

struct Left : Top 
{
    void print() { cout << "Left::print()" << endl; }
};

struct Bottom: Right, Left{};

int main()
{
    Bottom b;
    b.Right::Top::print();
}
Run Code Online (Sandbox Code Playgroud)

我想print()Top课堂上打电话.

当我尝试编译它时,我得到错误:'Top' is an ambiguous base of 'Bottom'在这一行:b.Right::Top::print(); 为什么它不明确?我明确规定,我想TopRight与不从 …

c++ inheritance multiple-inheritance diamond-problem

13
推荐指数
1
解决办法
704
查看次数