为什么运算符和相应的成员函数之间有区别?

问题描述 投票:0回答:1

为什么 Clang 17.0.1 中的运算符调用和相应的成员函数调用之间存在差异?他们不应该表现得一样吗?

#include <iostream>
    
struct A {
    void operator()(int) { std::cout << "A...\n"; }
};

struct B {
    void operator()(double) { std::cout << "B...\n"; }
};

template<typename... Ts> struct C : Ts... {};

int main() {
    C<A, B> c;
    c(1);
    c.operator()(1);
}

编译器资源管理器

来电

c(1);

有效,但是电话

c.operator()(1);

产生错误消息

error: member 'operator()' found in multiple base classes of different types

错误信息很明确。我很惊讶

c(1)
不会产生这个错误。

c++ language-lawyer multiple-inheritance
1个回答
0
投票

这似乎是修复的 clang 17.0.1 错误。这两个调用是等效的,并且在最新版本的 clang 等中产生相同的错误。

© www.soinside.com 2019 - 2024. All rights reserved.