gpt4 book ai didi

c++ - 指定使用 std::rotate 而不是来自 boost

转载 作者:行者123 更新时间:2023-11-27 23:48:12 25 4
gpt4 key购买 nike

我在指定使用来自 STL 的旋转而不是来自 boost 时遇到问题。我该怎么做?

下面是我的全部源码,是插入排序方法的简单代码

#include <algorithm>    // std::rotate
#include <vector>

// Function to sort the array
struct _ItemCompare {...} ItemCompare;

template<class T>
class Sorters {
public:
void insertionSort(std::vector<T> &vec, unsigned int size) {
for (auto it = vec.begin(); it != vec.begin() + size; it++) {
auto const insertion_point = std::upper_bound(vec.begin(), it, *it, ItemCompare);
std::rotate(insertion_point, it, it + 1);
}
}

};

error track trace可以看到如下代码:

In file included from src/balanced_intercalation_multipath.cpp:10:0,
from src/balanced_intercalation_multipath.h:29,
from main.cpp:7:
src/sorters.h: In member function ‘void Sorters<T>::insertionSort(std::vector<T>&, unsigned int)’:
src/sorters.h:29:19: error: ‘it’ does not name a type
for (auto it = vec.begin(); it != vec.begin() + size; it++) {
^
src/sorters.h:29:37: error: expected ‘;’ before ‘it’
for (auto it = vec.begin(); it != vec.begin() + size; it++) {
^
src/sorters.h:29:37: error: ‘it’ was not declared in this scope
In file included from src/balanced_intercalation_multipath.h:29:0,
from main.cpp:7:

In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.cpp:1:
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: note: synthesized method ‘Item& Item::operator=(const Item&)’ first required here
*__result = *__first;
^
src/sorters.h: In member function ‘void Sorters<T>::insertionSort(std::vector<T>&, unsigned int)’:
src/sorters.h:29:19: error: ‘it’ does not name a type
for (auto it = vec.begin(); it != vec.begin() + size; it++) {
^
src/sorters.h:29:37: error: expected ‘;’ before ‘it’
for (auto it = vec.begin(); it != vec.begin() + size; it++) {
^
src/sorters.h:29:37: error: ‘it’ was not declared in this scope

EDIT1:把我的整个代码和错误我用

编译

-lboost_serialization -std=c++11

最佳答案

您将获得 std::rotate , 但你忘了 #include <algorithm> .但是,您使用的 Boost header 已经为您包含了它。

但是,您收到的错误消息与 Boost 无关。

关于c++ - 指定使用 std::rotate 而不是来自 boost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48877176/

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