如何工作,而 basic_string 是一个有参数模板-6ren"> 如何工作,而 basic_string 是一个有参数模板-我这样定义一个字符串对象: string test; 我想知道STL是怎么实现string的,发现string是basic_string,像这样: typedef basic_string st-6ren">
cuốn sách gpt4 ai đã làm

c++ - 仅提供模板参数 "char"的 basic_string 如何工作,而 basic_string 是一个有参数模板

In lại Tác giả: Walker 123 更新时间:2023-11-28 02:01:46 25 4
mua khóa gpt4 Nike

我这样定义一个字符串对象:

string test;

我想知道STL是怎么实现string的,发现string是basic_string,像这样:

typedef basic_string string;

但是 basic_string 是这样的模板:

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

// Types:
công cộng:
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 iterator;
typedef __gnu_cxx::__normal_iterator
const_iterator;
typedef std::reverse_iterator const_reverse_iterator;
typedef std::reverse_iterator reverse_iterator;
......
}

我只是想知道 basic_string 是如何工作的,它只提供一个模板参数“char”,而 basic_string 实际上是一个有参数的模板

template

câu trả lời hay nhất

std::basic_string 有默认的模板参数。按照标准,声明是:

template,
class Allocator = allocator >
class basic_string

关于c++ - 仅提供模板参数 "char"的 basic_string 如何工作,而 basic_string 是一个有参数模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39197536/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress