In code below what is the difference between <Result (Arg0, Arg1)>
and <Result, Arg0, Arg1>
#include <cstddef>
#include <iostream>
using namespace std;
template <typename Result, typename Arg0 = void, typename Arg1 = void>
class Signal;
template <typename Result, typename Arg0, typename Arg1>
class Signal<Result (Arg0, Arg1)> // is this the same as <Result, Arg0, Arg1>
{
Result test(Arg0 arg0, Arg1 arg1)
{
}
};
int main()
{
Signal<void (int, int)> s; // or Signal<void, int, int>?
}
Result(Arg0, Arg1)
is a single type. It is read "function taking Arg0
and Arg1
returning Result
". When you specialize Signal
,
template <typename Result, typename Arg0, typename Arg1>
class Signal<Result(Arg0, Arg1)>
you've only given 1 argument, but it takes 3. The other 2 become the defaults, as stated in the template declaration. Thus, this is the same as
template <typename Result, typename Arg0, typename Arg1>
class Signal<Result(Arg0, Arg1), void, void>
Note that it makes absolutely no difference that the name of the parameters in the specialization match up with the declaration. The Arg0
in the specialization is different from the Arg0
in the declaration. In the specialization, Arg0
-from-the-declaration is not specified, which is why it defaults to void
. Similarly, in the declaration
Signal<void(int, int)> s;
you've really written
Signal<void(int, int), void, void> s;
I doubt you meant to do either of these things. Just use commas.
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