The following is the code:
namespace o
{
template <typename From, typename Tag> struct Alias;
template <typename From, typename Tag>
inline std::ostream &operator<<(std::ostream &stream, const Alias<From, Tag> &inst);
template <typename From, typename Tag> struct Alias final
{ ...... }
}
I was wondering, what is this template <typename From, typename Tag> struct Alias
. I know what is the meaning of a template function. Is this a template struct or something like that?
was wondering, what is this template struct Alias. I know what is the meaning of a template function. Is this a template struct or something like that?
That's exactly what it is.
Specifically, that line is a forward declaration, to allow you to use the template struct in a function before you actually define what is in the struct.
The following line(s):
<typename From, typename Tag> struct Alias final { ...... }
actually defines what's in the template struct.
Template structs work similarly to template functions in the sense that the compiler generates a specific case of the struct when it needs it. Like functions, template structs act as a blueprint for the compiler to generate classes from the blueprint when it needs to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.