Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
B.Eckel - Thinking in C++, Vol.2, 2nd edition.pdf
Скачиваний:
58
Добавлен:
08.05.2013
Размер:
2.09 Mб
Скачать

Explicit specification of template functions

Controlling template instantiation

Normally templates are not instantiated until they are needed. For function templates this just means the point at which you call the function, but for class templates it’s more granular than that: each individual member function of the template is not instantiated until the first point of use. This means that only the member functions you actually use will be instantiated, which is quite important since it allows greater freedom in what the template can be used with. For example:

//: C03:DelayedInstantiation.cpp

//Member functions of class templates are not

//instantiated until they're needed.

class X { public:

void f() {}

};

class Y { public:

void g() {}

};

template <typename T> class Z { T t;

public:

void a() { t.f(); } void b() { t.g(); }

};

int main() { Z<X> zx;

zx.a(); // Doesn't create Z<X>::b() Z<Y> zy;

zy.b(); // Doesn't create Z<Y>::a()

Chapter 15: Multiple Inheritance

144

Соседние файлы в предмете Численные методы
  • #
    08.05.20133.99 Mб25A.Menezes, P.van Oorschot,S.Vanstone - HANDBOOK OF APPLIED CRYPTOGRAPHY.djvu
  • #
  • #
    08.05.20135.91 Mб28B.Eckel - Thinking in Java, 3rd edition (beta).pdf
  • #
  • #
    08.05.20136.09 Mб20D.MacKay - Information Theory, Inference, and Learning Algorithms.djvu
  • #
    08.05.20133.85 Mб19DIGITAL Visual Fortran ver.5.0 - Programmers Guide to Fortran.djvu
  • #
    08.05.20131.84 Mб16E.A.Lee, P.Varaiya - Structure and Interpretation of Signals and Systems.djvu