我只是遇到了一个奇怪的问题,该问题仅在带有Clion的MSVC上发生,而在其他编译器上没有发生(我在Linux和Visual Studio上尝试了gcc,但在相同的代码下都没有这种问题)。
使用以下代码:
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int>v = {1,2,3,4,5};
make_heap(v.begin(), v.end());
v.push_back(6);
push_heap(v.begin(), v.end());
}
错误“在实例化功能模板专门化'std::push_heapstd::_ Vector_iterator 是Clion或MSVC的错误吗?
附言
我仍然可以构建和运行它,因此它可能不是编译器错误。 (让我更加困惑)
最佳答案
看来您无法使用以下命令初始化vector:
vector<int>v = {1,2,3,4,5};
更改为:vector<int> vect{ 1, 2, 3, 4, 5 };
编译并运行代码,看看它是否仍然有问题。编辑:
有人说这不太可能,但是请查看链接:
What is the easiest way to initialize a std::vector with hardcoded elements?
如果向下滚动到第二个答案,它将显示:
If your compiler supports C++11, you can simply do:
std::vector<int> v = {1, 2, 3, 4};
由于您没有告诉我们您的编译器版本和环境,因此很难确定这是否是问题所在。另请注意:This is available in GCC as of version 4.4.
Unfortunately, VC++ 2010 seems to be lagging behind in this respect.
因此,如果您使用的是VC++的旧版本,那么您就不走运了...
关于c++ - make_heap和pop_heap可以,但是push_heap不能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62964237/