std::array 作为另一个标准容器的元素类型?
std::array as element type of another standard container?
似乎没有任何规则反对它,我遇到的错误
std::vector< std::array<int,8> > output;
output.resize (8);
是C2036 'std::array<int,0x08> *': unknown size
这没有意义。 <vector>
中的代码正在推进内部 end
指针,该指针也在其他地方使用(作为扩展的计算大小)。 struct{int x[8];}
的大小肯定是“已知”的。
这是怎么回事?
嗯,因为它不仅仅是一个简单的错字之类的,而且当其他人尝试它时似乎工作正常(并且其他人写的示例对我有用!)我削减了源文件直到除了冒犯性的陈述,它仍然失败。这是整个文件。预编译 headers 已关闭。
//#include <SDKDDKVer.h>
#include <vector>
int main()
{
std::vector< std::array<int,8> > output;
output.resize (16);
}
我正在使用 x64 构建,发布构建。
想通了:
vector
没有缺少#include,array
没有!
在其他 headers 中显然是 forward-declared 但不完整。
这段代码似乎一切正常。
#include <vector>
#include <array>
int main() {
std::vector< std::array<int,8> > output;
output.resize(8);
return 0;
}
您是否添加了 #include <array>
行?
似乎没有任何规则反对它,我遇到的错误
std::vector< std::array<int,8> > output;
output.resize (8);
是C2036 'std::array<int,0x08> *': unknown size
这没有意义。 <vector>
中的代码正在推进内部 end
指针,该指针也在其他地方使用(作为扩展的计算大小)。 struct{int x[8];}
的大小肯定是“已知”的。
这是怎么回事?
嗯,因为它不仅仅是一个简单的错字之类的,而且当其他人尝试它时似乎工作正常(并且其他人写的示例对我有用!)我削减了源文件直到除了冒犯性的陈述,它仍然失败。这是整个文件。预编译 headers 已关闭。
//#include <SDKDDKVer.h>
#include <vector>
int main()
{
std::vector< std::array<int,8> > output;
output.resize (16);
}
我正在使用 x64 构建,发布构建。
想通了:
vector
没有缺少#include,array
没有!
在其他 headers 中显然是 forward-declared 但不完整。
这段代码似乎一切正常。
#include <vector>
#include <array>
int main() {
std::vector< std::array<int,8> > output;
output.resize(8);
return 0;
}
您是否添加了 #include <array>
行?