Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有自定义类的循环范围(vector<;string>;的简单版本,使用分配器) 我现在正在通过C++入门第五版。今天我已经谈到了处理动态内存的类。鉴于以下概念: class StrVec{ public: StrVec() : // the allocator member is default initialized elements(nullptr), first_free(nullptr), cap(nullptr) {} StrVec(const StrVec&); StrVec(std::initializer_list<std::string>); StrVec& operator=(const StrVec&); ~StrVec(); std::string* begin() const { return elements; } std::string* end() const { return first_free; } //other functions private: std::allocator<std::string> alloc; std::string *elements; std::string *first_free; std::string *cap; //other functions }; class StrVec{ 公众: StrVec()://分配器成员默认已初始化 元素(空PTR), 第一个自由(空PTR), cap(nullptr){} StrVec(const-StrVec&); StrVec(标准::初始值设定项列表); StrVec&运算符=(const StrVec&); ~StrVec(); std::string*begin()常量{return elements;} std::string*end()常量{return first_free;} //其他职能 私人: 分配程序alloc; std::string*元素; std::string*第一个\u空闲; std::string*cap; //其他职能 };_C++ - Fatal编程技术网

具有自定义类的循环范围(vector<;string>;的简单版本,使用分配器) 我现在正在通过C++入门第五版。今天我已经谈到了处理动态内存的类。鉴于以下概念: class StrVec{ public: StrVec() : // the allocator member is default initialized elements(nullptr), first_free(nullptr), cap(nullptr) {} StrVec(const StrVec&); StrVec(std::initializer_list<std::string>); StrVec& operator=(const StrVec&); ~StrVec(); std::string* begin() const { return elements; } std::string* end() const { return first_free; } //other functions private: std::allocator<std::string> alloc; std::string *elements; std::string *first_free; std::string *cap; //other functions }; class StrVec{ 公众: StrVec()://分配器成员默认已初始化 元素(空PTR), 第一个自由(空PTR), cap(nullptr){} StrVec(const-StrVec&); StrVec(标准::初始值设定项列表); StrVec&运算符=(const StrVec&); ~StrVec(); std::string*begin()常量{return elements;} std::string*end()常量{return first_free;} //其他职能 私人: 分配程序alloc; std::string*元素; std::string*第一个\u空闲; std::string*cap; //其他职能 };

具有自定义类的循环范围(vector<;string>;的简单版本,使用分配器) 我现在正在通过C++入门第五版。今天我已经谈到了处理动态内存的类。鉴于以下概念: class StrVec{ public: StrVec() : // the allocator member is default initialized elements(nullptr), first_free(nullptr), cap(nullptr) {} StrVec(const StrVec&); StrVec(std::initializer_list<std::string>); StrVec& operator=(const StrVec&); ~StrVec(); std::string* begin() const { return elements; } std::string* end() const { return first_free; } //other functions private: std::allocator<std::string> alloc; std::string *elements; std::string *first_free; std::string *cap; //other functions }; class StrVec{ 公众: StrVec()://分配器成员默认已初始化 元素(空PTR), 第一个自由(空PTR), cap(nullptr){} StrVec(const-StrVec&); StrVec(标准::初始值设定项列表); StrVec&运算符=(const StrVec&); ~StrVec(); std::string*begin()常量{return elements;} std::string*end()常量{return first_free;} //其他职能 私人: 分配程序alloc; std::string*元素; std::string*第一个\u空闲; std::string*cap; //其他职能 };,c++,C++,和一个StrVec对象StrVec foo={“stack”,“overflow”},循环的范围是如何精确地工作的(for(auto&el:foo)std::cout 我正在迭代的“东西”是什么 由foo.begin()和foo.end()的结果分隔的范围 是的,这些函数名是“特殊的”在这方面。称之为标准认可的约定。你是在问动态内存分配,还是关于?你忽略了循环范围所需的关键成员函数…你实际上在问什么?关于这个问题的答案。那么这是什么?@johniewh至少没有begin()的声明和end()无法

和一个
StrVec
对象
StrVec foo={“stack”,“overflow”}
,循环的范围是如何精确地工作的(
for(auto&el:foo)std::cout
我正在迭代的“东西”是什么

foo.begin()
foo.end()
的结果分隔的范围


是的,这些函数名是“特殊的”在这方面。称之为标准认可的约定。

你是在问动态内存分配,还是关于?你忽略了循环范围所需的关键成员函数…你实际上在问什么?关于这个问题的答案。那么这是什么?@johniewh至少没有
begin()的声明
end()
无法判断超
StrVec
会做什么(除了导致编译错误)。感谢@Biffen and Lightness Races in Orbit的答案,我现在得到了:D