2
可有人請解釋什麼規則確定編譯器調用函數對象f
下方而不是函數f
的?編譯器選擇了仿函數同名
#include <iostream>
struct A {
void operator()() { std::cout << "functor" << std::endl; }
};
void f() { std::cout << "function" << std::endl; }
int main()
{
A f;
f(); // Output: functor
}
A::operator()()
和f()
不超載,所以我的猜測是這種情況發生重載決議之外。