简明问题
请考虑以下函数:
class NonTrivialClass { /* ... */ };
void f1(NonTrivialClass &) {}
void f2(NonTrivialClass const&) {}
是否有一个表达式可以调用f1
,但不能将f1
替换为f2
?
背景
在一份工作的前景中,我被要求“编写方法double approx(vector<Point>& pts)
”(给出Point
),该方法使用来自pts
的点以类似Buffon的方式逼近已知常量。
我已经编写了实现定义double approx(vector<Point> const& pts)
的代码(请注意const
)。但由于某种原因,我未能通过测试!
在排除所有可能的解释后,我对测试平台和那个关键的const
限定符产生了疑问...他们的测试程序是否可以使用double approx(vector<Point>& pts)
而不是double approx(vector<Point> const& pts)
?
vector
而不是std::vector
的测试,也许你就不应该相信它。 ;) - Holtusing namespace std;
。但是让我们不要偏离主题。 - YSC#include "contestant_code.cc"
一样。而在骨架答案中有一个开始的using namespace std;
,我将其删除了……测试程序期望编译vector<Point>
,但现在无法编译 => 测试失败。 - YSC