class-template-Instantiierung

Gerade lese ich den wiki-Artikel über CRTP, und ich bin ein wenig verwirrt über die template-Instantiierung.

Laut wiki,

member-Funktion stellen (Definitionen) sind nicht instanziiert, bis lange
nach Ihren Erklärungen.

Ich verstehe nicht ganz, was es bedeutet.

Angenommen ich habe eine Klasse Vorlage:

template <typename T>
class A
{
    public:
        void foo(T t)
        {
            //...
        };
};

Wenn ich die Klasse instanziieren template Ein, oder tut es das instanziieren der member-Funktion foo()?

Beispiel:

//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?
}
InformationsquelleAutor Alcott | 2011-11-21
Schreibe einen Kommentar