vendredi 10 juillet 2020

C++ Why Traits are not available on objects but rather are available as static member variables

My understanding about class Traits is that it is a class that encapsulates a set of types and functions necessary for template classes and template functions to manipulate objects of types for which they are instantiated.

In below example why we cannot make use of 'gquiz::container_type' declaration else how would we know the traits of gquiz :

int main()
{
    queue <int> gquiz;
    const queue <int>::container_type dq;
    //why not gquiz::container_type ?????
    cout << typeid(dq).name() << endl;
    gquiz.push(10);
    gquiz.push(queue <int>::value_type(20));
    gquiz.push(30);
}

Aucun commentaire:

Enregistrer un commentaire