gpt4 book ai didi

c++ - C++11 段错误中基于范围的 for 循环,但不是常规 for 循环

转载 作者:可可西里 更新时间:2023-11-01 18:36:07 26 4
gpt4 key购买 nike

<分区>

//fills my vector with pointers.
//(some are pointing places, others are set to nullptr
vector<Tree_NodeT*> xml_trees {Build_Tree_List(program_options->Get_Files())};

//time to print them
for (auto tree = xml_trees.begin(); tree != xml_trees.end(); ++tree){
if (*tree){
(*tree)->Print(std::cout,4);
}
}
//this worked! No Segfaults!

//time to print them again
for (auto tree : xml_trees){
if (tree){
tree->Print(std::cout,4);
}
}
//Crash! Segfault.

为什么第二个循环有段错误,而第一个循环没有?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com