【发布时间】:2016-06-13 05:40:06
【问题描述】:
#include <vector>
#include <functional>
int main(int argc, char** argc)
{
std::vector<int> x;
std::function<void (void)> f(std::allocator_arg,x.get_allocator());
return 1;
}
使用:g++ test.cpp -o test -std=c++11
它在Ubuntu 15,我的g++ version is 5.2.1 上失败了。 XCode 和 VS2015 一切正常。我检查了/usr/include/c++/5/functional,它没有分配器的构造函数。我检查了www.cplusplus.com,它用分配器定义了构造函数。
有人可以告诉我如何解决这个问题,或者我必须更改 g++ stl,
如何用其他 stl 更改 g++ stl?我已经下载了 sgi stl 源代码。
请帮忙 !非常感谢。
【问题讨论】:
-
allocator_arg是一个常量 - 你的代码没有比std::function<void (void)> f(PI);更有意义。 -
直到 GCC 6.1.0,
std::functionwith allocator 仍然不被支持,来源有评论// TODO: needs allocator_arg_t -
非常感谢。我放弃使用分配器了~