[英]What is the meaning of "const Allocator& alloc = Allocator()"?
I refer to c++ std::string constructor on both cplusplus.com and cppreference.com .我在cplusplus.com和cppreference.com上都引用了 c++ std::string 构造函数。
And I find the syntax on cppreference.com is more complex to me.我发现 cppreference.com 上的语法对我来说更复杂。 On the contrary, cplusplus.com is clearer and easier to understand.相反,cplusplus.com 更清晰易懂。
For example:例如:
// cplusplus.com
string (const string& str, size_t pos, size_t len = npos);
// cppreference.com
basic_string( const basic_string& other,
size_type pos,
size_type count = std::basic_string::npos,
const Allocator& alloc = Allocator() );
I wonder why " const Allocator& alloc = Allocator() " appears here and why it is needed (I am not sure if it is omitted by default while constructing).我想知道为什么“ const Allocator& alloc = Allocator() ”出现在这里以及为什么需要它(我不确定在构建时是否默认省略了它)。
It would be more helpful if anyone can show more differences between the two references in details.如果有人可以详细显示两个参考文献之间的更多差异,那将会更有帮助。 Thank you!谢谢!
What is the meaning of “const Allocator& alloc = Allocator()”? “const Allocator& alloc = Allocator()”是什么意思?
In this context, this is syntax for a function parameter.在这种情况下,这是函数参数的语法。 It allows arguments to be passed into functions.它允许将参数传递给函数。
I wonder why "const Allocator& alloc = Allocator()" appears here我想知道为什么“const Allocator& alloc = Allocator()”出现在这里
It appears so that an allocator could be passed as an argument.似乎可以将分配器作为参数传递。
and why it is needed以及为什么需要它
Because The container supports custom allocators.因为容器支持自定义分配器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.