在 S. Lippman 撰写的“C++ 对象模块内部”的第 26 页上,您会发现以下代码段:
void rotate(
X datum,
const X *pointer,
const X &reference )
{
// cannot determine until run-time
// actual instance of rotate() invoked
(*pointer).rotate();
reference.rotate();
// always invokes X::rotate()
datum.rotate();
}
main() {
Z z; // a subtype of X
rotate( z, &z, z );
return 0;
}
这一段:
The two invocations through pointer and reference are resolved dynamically. In this example, they both
invoke Z::rotate(). The invocation through datum may or may not be invoked through the virtual
mechanism; however, it will always invoke X::rotate().
AFAIK,datum.rotate()
将始终通过静态调用调用。为什么编译器会在这里使用虚拟调用?