What does this construct A <B> :: c ("d") mean? Space name with pattern?
It appears to be ca function that takes "d" as an argument. I know what is ::used for the specified namespaces and their namespaces. But what does it mean A<B>? I know what Ba class is. I also know that templates can be used for classes, functions, and structures. But in this example, it looks like we are using a template for a namespace.
+5
2 answers
This means that you have a class template Athat takes a type parameter, and you create this template with the type Bas its type argument.
, , (1) c ( ), , (2) c , ( ).
, A, (::), , ( , , ).
#include <iostream>
struct B { };
template<typename T>
struct A
{
static void c(const char* s) { std::cout << s; }
};
int main()
{
A<B>::c("d");
}
#include <iostream>
struct B { void operator () (const char* c) { std::cout << c; } };
template<typename T>
struct A
{
static T c;
};
template<typename T>
T A<T>::c;
int main()
{
A<B>::c("d");
}
#include <iostream>
struct B { B(const char* s) { std::cout << s; } };
template<typename T>
struct A
{
typedef T c;
};
int main()
{
A<B>::c("d");
}
+10
c() A<B>. .
, c (, , operator()(const char *))), const char * class struct, A<B>, const char *.
( , .)
+7