I am looking at someone’s code, I don’t understand how the object getting initialized here:
template <typename String>
void test_numbers()
{
SampleClass<String> compare;
String lhs = "abc";
String rhs = "efg";
check_equality(compare(lhs, rhs), true);
}
The object compare is created of class type SampleClass and then assigned 2 strings when passed on as a parameter. How this initialization works? Any comments? suggestions?
compare is already constructed. It has an
operator()implemented that allows it to appear as a function, accepting arguments.you can make your own easily.
The reason this is useful is because we can do thing like this.
see here:
http://msdn.microsoft.com/en-us/library/5tk49fh2(v=vs.80).aspx
useful with
http://en.cppreference.com/w/cpp/algorithm