2016-08-29 6 views
0

が、パラメータであり、は、私は、このような文字列オブジェクトを定義するテンプレート

typedef basic_string<char> string; 

しかしのbasic_stringは、このようなテンプレートです:

template<typename _CharT, typename _Traits, typename _Alloc> 
class basic_string 
{ 
    typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; 

    // Types: 
public: 
    typedef _Traits      traits_type; 
    typedef typename _Traits::char_type   value_type; 
    typedef _Alloc      allocator_type; 
    typedef typename _CharT_alloc_type::size_type  size_type; 
    typedef typename _CharT_alloc_type::difference_type difference_type; 
    typedef typename _CharT_alloc_type::reference  reference; 
    typedef typename _CharT_alloc_type::const_reference const_reference; 
    typedef typename _CharT_alloc_type::pointer  pointer; 
    typedef typename _CharT_alloc_type::const_pointer  const_pointer; 
    typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; 
    typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> 
                 const_iterator; 
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 
    typedef std::reverse_iterator<iterator>   reverse_iterator; 
    ...... 
} 
と私はその文字列はこのように、のbasic_stringされました

私はただ一つだけのテンプレートパラメータに「char」を提供するのbasic_stringは、どのように動作するかのbasic_stringは文字通り

template<typename _CharT, typename _Traits, typename _Alloc> 

答えて

2

std::basic_stringは、デフォルトのテンプレート引数を持っているが、パラメータのテンプレートである一方であることkownたいです。標準によると、宣言は次のとおりです。

template<class charT, class traits = char_traits<charT>, 
    class Allocator = allocator<charT> > 
class basic_string 
+0

私はちょうどあなたが見ることができる/usr/include/c++/4.8/bits/basic_string.hでのbasic_stringのソースコードを再チェック: 'テンプレート class basic_string' – cong

+0

@ Brian、ありがとう、/usr/include/c++/4.8/bits/stringfwd.hで宣言されています。 – cong

関連する問題