最烦人的解析我从这里.class Timer {
public:
Timer();};class TimeKeeper {
public:
TimeKeeper(const Timer& t);
int get_time()
{
return 1;
}};int main() {
TimeKeeper time_keeper(Timer());
return time_keeper.get_time();}从它的外观来看,它应该会得到编译错误,原因是行:TimeKeeper time_keeper(Timer());但只有当return time_keeper.get_time();是存在的。为什么这一行甚至重要,编译器会发现歧义time_keeper(Timer() )建筑。
2 回答
心有法竹
TA贡献1866条经验 获得超5个赞
TimeKeeper time_keeper(Timer());
get_time()
int main() { // time_keeper gets interpreted as a function declaration with a function argument. // This is definitely *not* what we expect, but from the compiler POV it's okay. TimeKeeper time_keeper(Timer (*unnamed_fn_arg)()); // Compiler complains: time_keeper is function, how on earth do you expect me to call // one of its members? It doesn't have member functions! return time_keeper.get_time();}
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
虽然我知道标准在第13.1/3节中说,在这种情况下,定时器函数类型会被调整成为函数类型的指针,但是为什么有人希望从一开始就对其进行调整呢?在我看来,第13.1/3节造成了整个“最令人烦恼的解析”问题?
- 2 回答
- 0 关注
- 419 浏览
添加回答
举报
0/150
提交
取消