如何转储候选人在函数重载分辨率? [英] How to dump candidates in function overload resolution?
问题描述
如何转储函数调用的候选函数(或可行函数或最佳可行函数)?
How can I dump candidate functions (or viable functions or best viable functions) for a function invocation?
我知道g ++提供了选项转储类层次结构。 (事实上,Visual Studio 2010提供了一个类似的选项,但它没有记录,我记得读一些关于它 - 也许在VC ++团队博客,但我不记得清楚。)
I know g++ provides an option to dump class hierarchy. (In fact, Visual Studio 2010 provides a similar option, but it's undocumented. I remember reading something about it—maybe in the VC++ team blog—but I can't remember it clearly.)
最近,我一直在阅读关于C ++ 0x草案中的重载解析,它真的让我很尴尬。
Recently, I have been reading about overload resolution in the C++0x draft, and it really embarrassed me.
有没有任何编译器提供一个选项转储候选函数,可行函数或最佳可行函数?
Does any compiler provide an option to dump candidate functions, viable functions, or best viable functions?
注意:重载分解场景中的候选函数不同于候选函数编译错误。在过载解决方案中的候选/可行/最佳可行函数具有它们自己的意义。我知道他们是重载决议的三个阶段:找到候选函数;找到可行的功能;
找到最好的可行函数。通常,最好的可行功能只是一个候选人;否则,调用是不明确的。每个阶段都有自己的规则。
Note: The candidate functions in overload resolution scenario is different from the candidate functions in the compiler error. The candidate/viable/best viable function in overload resolution scenario has their own meaning. I know their are three stages in overload resolution: find the candidate functions; find the viable functions; find the best viable functions. Normally, the best viable function is just one candidate; otherwise, the call is ambiguous. Each stage has their own rules.
推荐答案
我认为没有任何直接的方法。
I don't think there is any direct way.
一种方法是人为地故意造成冲突/歧义。大多数编译器发出以下形式的错误,抛出所考虑的候选者列表。
One way is to deliberately create a conflict/ambiguity artificially. Most compilers emit an error of the form below, spewing out the list of considered candidates.
namespace A {
void f(int x) {}
}
void f(int x) {}
void f(char x) {}
using namespace A;
int main(){
f(2.2);
}
G ++错误讯息:
prog.cpp: In function ‘int main()’:
prog.cpp:10: error: call of overloaded ‘f(double)’ is ambiguous
prog.cpp:4: note: candidates are: void f(int)
prog.cpp:5: note: void f(char)
prog.cpp:2: note: void A::f(int)
这篇关于如何转储候选人在函数重载分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!