Thank you for the template tutorial on the flow of chicory to the empty Ming Dynasty:
Https://github.com/wuye9036/CppTemplateTutorial
This article is to give yourself a quick reference to recall, not necessarily suitable for others to see.
#include <iostream>
usingnamespaceStd
Template <typename t>classAddfloatormulint
{
Statict do (t A, T B)
{
//In this example, the general form of what is not important, because it is not used
//just give me a 0 here.
returnT0);
}
};
//second, we want to specify that T is the code for int, which is the Special:
Template <>classaddfloatormulint<int>
{
Public:
StaticintDo (intAintb//
{
returnA * b;
}
};
//again, we want to specify that T is the code at float time:
Template <>classaddfloatormulint<float>
{
Public:
StaticfloatDo (floatAfloatb
{
returnA + b;
}
};
intMain ()
{
intresult = addfloatormulint<int::D O (1,2);
cout<<result;
GetChar ();
return0;
}
/*
Let's take a look at the special form: It's a bit strange: template <> class addfloatormulint<int>. Don't worry, I'll explain it to you.
What is the basic form of our template?
Template <typename t> class Addfloatormulint;
But this class is for T is int, so we write
Class addfloatormulint<int>
Of course, compiling here is not a pass.
But it is not an ordinary class, but a specialization of class templates (special cases).
So I'm going to add template keyword templates to the front,
and a list of template parameters
Template < What to fill in here? > class addfloatormulint<int>;
Finally, what does the template parameter list fill in? Because the prototype T has been replaced by Int. So you can't put any extra parameters here.
So here we go.
Template <> class addfloatormulint<int>
{
// ... implementation for int ...
}
Bingo!
*/
C + + Template Contact Summary