Właśnie przeczytałem artykuł wiki o CRTP, a ja jestem nieco zdezorientowany w kwestii tworzenia szablonów.Utworzenie szablonu klasy
Według wiki,
ciała funkcji składowej (Definicje) nie są aż instancja długi po ich deklaracji.
Nie bardzo rozumiem, co to znaczy.
Załóżmy Mam klasy szablonu:
template <typename T>
class A
{
public:
void foo(T t)
{
//...
};
};
Kiedy instancję klasy szablonu A, to instancję member function foo()?
Na przykład:
//in .cpp file
int main()
{
A<int> a; //question 1
//class template is instantiated here, isn't it?
//What about foo(), is it instantiated too?
a.foo(10); //question 2
//according to the quotation, foo() will not be instantiated until it is used.
//if so, foo() is instantiated right here, not in question 1, right?
}
Plug: To może odpowiedzieć na Twoje pytania: http: // stackoverflow.com/questions/7182359/template-instantiation-details-of-gcc-and-ms-compilers/7241548 # 7241548 –