小编Ста*_*ько的帖子

c ++静态成员函数重载继承

我有以下代码:

struct CommonVariables
{/*some common variables that need to be proceed*/};

struct CommonHandler
{
    static void foo(const CommonVariables& vars) {/*processed vars*/}
    void bar(const CommonVariables& vars) {/*processed vars*/}
};

struct AnotherVariables
{/*another variables*/};

struct AnotherHandler
{
    static void foo(const AnotherVariables& vars) {/*processed vars*/}
    void bar(const AnotherVariables& vars) {/*processed vars*/}
};

struct Derived : CommonHandler, AnotherHandler
{};
Run Code Online (Sandbox Code Playgroud)

当我尝试调用 Derived::foo(/ any variable type /) 或 Derived d; d.bar(/ any variable type /),编译器给我一个错误:“对'foo(or bar)'的引用不明确”。

然而在下面我有几乎相同的情况:

struct DifferentHandler
{
static void foo(const CommonVariables& vars) {} …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance static-methods

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

标签 统计

c++ ×1

inheritance ×1

static-methods ×1