为什么 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)
不会产生这个错误。
这似乎是修复的 clang 17.0.1 错误。这两个调用是等效的,并且在最新版本的 clang 等中产生相同的错误。