我刚刚遇到了一个奇怪的问题,这个问题只在带有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());
}然后将显示错误"In instantiation of function template specialization 'std::push_heapstd::_Vector_iterator >‘no type named 'value_type’in 'std::indirectly_readable_traitsstd::_Vector_iterator >'“

是Clion还是MSVC的bug?
附言:我仍然可以构建和运行它,所以它可能不是一个编译器错误;(这让我更加困惑)
发布于 2020-07-18 11:24:57
看起来你不能用下面的命令初始化向量:
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++,那么您就不走运了……
https://stackoverflow.com/questions/62964237
复制相似问题