error C2039: “push_front”: 不是“std::vectorint,std::allocator”的成员

本文解决了一个关于使用push_front方法在std::vector上引发的编译错误。错误代码尝试使用unique_copy将元素添加到vector的前端,但std::vector并未直接提供push_front方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误代码:

unique_copy(ivec.cbegin(), ivec.cend(), front_inserter(ivec));
    for (auto i : ivec)
        cout << i;
    cout << endl;

报错:错误 1 error C2039: “push_front”: 不是“std::vector

for (auto e = boost::edges(sdMap).first; e != boost::edges(sdMap).second; ++e) { auto start = std::chrono::high_resolution_clock::now(); const OsmEdgeProperties &edgeProps = sdMap[*e]; // get vertices geometry LineString linestring_global; std::string line_geometry_string = edgeProps.geometry; if (line_geometry_string.empty()) { boost::adjacency_list<>::vertex_descriptor source = boost::source(*e, sdMap); boost::adjacency_list<>::vertex_descriptor target = boost::target(*e, sdMap); if (source == target) continue; line_geometry_string = "LINESTRING ("; const OsmNodeProperties &startNodeProps = sdMap[*(vertices_pair.first + source)]; line_geometry_string = line_geometry_string + startNodeProps.x + " " + startNodeProps.y + ", "; const OsmNodeProperties &endNodeProps = sdMap[*(vertices_pair.first + target)]; line_geometry_string = line_geometry_string + " " + endNodeProps.x + " " + endNodeProps.y + ")"; } // auto end = std::chrono::high_resolution_clock::now(); boost::geometry::read_wkt(line_geometry_string, linestring_global); // auto end = std::chrono::high_resolution_clock::now(); // auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); // std::cout << "sdmap encode timer delay : " << delay << std::endl; // get Properties std::string fclass = edgeProps.fclass; std::vector<std::string> fclass_explode; if (fclass.front() == '[' && fclass.back() == ']') { fclass = fclass.substr(1, fclass.size() - 2); fclass.erase(std::remove_if(fclass.begin(), fclass.end(), ::isspace), fclass.end()); boost::split(fclass_explode, fclass, boost::is_any_of(",")); } else { fclass_explode.push_back(fclass); } for (size_t i = 0; i < fclass_explode.size(); i++) { fclass = "other"; for (const auto &pair : HIGHWAY_SETS) { if (pair.second.find(fclass_explode[i]) != pair.second.end()) { fclass = pair.first; break; } } fclass_explode[i] = fclass; } // transform geometry to local coordinate LineString linestring_local; transformGlobalToEgo(transformationMatrix, linestring_global, linestring_local); std::vector<LineString> inner_lines; // crop try { if (crop) { get_inner_lines(canvas_polygon, linestring_local, inner_lines); } else { inner_lines.push_back(linestring_local); } } catch (const std::exception &e) { std::cerr << "error: " << e.what() << std::endl; continue; } // 将裁剪得到的线段加入结果 for (std::string sub_fclass : fclass_explode) { for (LineString inner_line : inner_lines) { EdgeInfo edge_info{fclass, inner_line}; edges_info.push_back(edge_info); } } } 分析并理解这段代码,发现耗时逐渐递增主要发生在这行段for循环里。
06-14
错误有错误 2 error C3861: “accumulate”: 找不到标识符 c:\users\sqpsk\desktop\小学期数据结构\consoleapplication8\consoleapplication8\consoleapplication8.cpp 85 1 ConsoleApplication8 错误 3 error C2664:std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)”: 无法将参数 1 从“char”转换为“const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &” c:\users\sqpsk\desktop\小学期数据结构\consoleapplication8\consoleapplication8\consoleapplication8.cpp 85 1 ConsoleApplication8 5 IntelliSense: "TreeNode *" 类型的值不能用于初始化 "TreeNode *" 类型的实体 c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 32 26 ConsoleApplication8 6 IntelliSense: "TreeNode *" 类型的值不能用于初始化 "TreeNode *" 类型的实体 c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 43 26 ConsoleApplication8 7 IntelliSense: 未定义标识符 "accumulate" c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 85 16 ConsoleApplication8 8 IntelliSense: "TreeNode *" 类型的值不能用于初始化 "TreeNode *" 类型的实体 c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 105 26 ConsoleApplication8 9 IntelliSense: "TreeNode *" 类型的值不能用于初始化 "TreeNode *" 类型的实体 c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 122 27 ConsoleApplication8 10 IntelliSense: "TreeNode *" 类型的值不能用于初始化 "TreeNode *" 类型的实体 c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 143 27 ConsoleApplication8 11 IntelliSense: 没有与参数列表匹配的 重载函数 "std::vector<_Ty, _Alloc>::push_back [其中 _Ty=TreeNode *, _Alloc=std::allocator<TreeNode *>]" 实例 参数类型为: (TreeNode *) 对象类型是: std::vector<TreeNode *, std::allocator<TreeNode *>> c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 187 23 ConsoleApplication8 12 IntelliSense: 操作数类型不兼容("TreeNode *" 和 "TreeNode *") c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 206 12 ConsoleApplication8 13 IntelliSense: "TreeNode *" 类型的值不能用于初始化 "TreeNode *" 类型的实体 c:\Users\sqpsk\Desktop\小学期数据结构\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.cpp 297 28 ConsoleApplication8
07-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值