R
R
ReD2020-06-21 16:10:16
C++ / C#
ReD, 2020-06-21 16:10:16

How to understand a function call inside another function with a different number of parameters?

While analyzing the unit test example, I came across the following piece of code:

void Assert(bool b, const string& hint) {
 AssertEqual(b, true, hint); 
}


But the author did not properly explain how it works,
and he confuses me. Two parameters are passed to the function, and another one is called inside the function itself, but with three parameters. It's not entirely clear somehow...

AssertEqual itself is implemented via a template:

void AssertEqual (class T& t, const U& u, const string& hint) { if (t != u) {
ostringstream os;
os << "Assertion failed: " << t << "!=" << u << "Hint: " << hint; throw runtime_error(os);
 } }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor Bomberow, 2020-06-21
@trinitr0

In short, the first Assert function needs to be renamed to AssertIsTrue , and the hint parameter to errorMsg . There should be text that will explain in runtime_error where the b parameter value from the Assert function came from . For example, a function name with arguments or a variable name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question