Please consider the following functions:
class NonTrivialClass { /* ... */ };
void f1(NonTrivialClass &) {}
void f2(NonTrivialClass const&) {}
Is there an expression invoking f1 in which one could not replace f1 with f2?
In the prospect of a job offering, I've been asked "to write the method double approx(vector<Point>& pts)" (Point being given) which uses points from pts to approximate a known constant in a Buffon-like way.
I have written an implementation defining double approx(vector<Point> const& pts) (note the const). And for a reason yet to determine, I've failed the test!
After removing all possible explanation, I'm left with doubts about the test platform and that gripping const qualifier... Is it possible that their test program would have worked with double approx(vector<Point>& pts) but not with double approx(vector<Point> const& pts)?
If your question admits insane answers:
struct NonTrivialClass {};
struct NonTrivialClass2 {
operator NonTrivialClass&();
operator NonTrivialClass const&();
};
void f1(NonTrivialClass &) {}
void f2(NonTrivialClass const&) {}
int main()
{
NonTrivialClass2 foo;
f1(foo);
f2(foo); // error: reference initialization is ambiguous
}
of course, this doesn't apply to the vector<> case (unless the test machinery passes some kind of 'tester' object with a broken (maybe templated, sfinae-unfriendly-whatever) converting operator to some wrapped vector member ? seems unreasonable ... but not impossible)
If there was such an expression (apart from such cases where f2 was inaccessible for any reason), that would break my own C++ knowledge entirely...
I consider it much more likely that you implemented a minimal bug (you are not yet aware of) in your function leading to failure; cannot exclude, though, that the test evaluation software is dumb enough just to look for a fix, given signature, no matter if yours is compatible or not...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With