what's the purpose of typename assignment inside templates

前端 未结 6 922
后悔当初
后悔当初 2021-01-02 08:07

I have come across this piece of code (I\'m trying to include all details in case I\'m missing something):

template< typename TYPE = TYPE_with_an_arbitrar         


        
6条回答
  •  暖寄归人
    2021-01-02 08:25

    These are default template arguments. You can use template default arguments to simplify their usage.

    When you have two template parameters, for example, and give the last one a default type, you must specify only one type.

    std::vector, for example, is defined as

    template < class T, class Allocator = allocator > class vector;
    

    Here you have a default template argument for Allocator, so you can define vectors with just one argument

    std::vector v;
    

提交回复
热议问题