【发布时间】:2013-02-15 20:27:13
【问题描述】:
我想试试新的Hinnant's short_alloc allocator,据我所知,它取代了旧的stack_alloc 分配器。但是,我无法编译矢量示例。 g++ 说:
~# g++ -std=c++11 stack-allocator-test.cpp -o stack-allocator-test
In file included from stack-allocator-test.cpp:6:0:
short_alloc.h:11:13: error: ‘alignment’ is not a type
short_alloc.h:11:22: error: ISO C++ forbids declaration of ‘alignas’ with no type [-fpermissive]
short_alloc.h:11:22: error: expected ‘;’ at end of member declaration
据我所知,g++ 抱怨 line 10 和 11:
static const std::size_t alignment = 16;
alignas(alignment) char buf_[N];
编译器似乎不喜欢 alignas 的“表达式版本”,但它只需要“类型 ID 版本”。
我在 Ubuntu 12.10 下使用 g++ 4.7.2。
~# g++ --version
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
可能我遗漏了一些明显的东西,但我无法弄清楚。任何帮助,将不胜感激。 (请不要告诉我我必须升级到更新的g++,我懒得这么做了:)
【问题讨论】:
-
是的,我也是这么想的,但是应该定义
std::size_t,因为正确包含<cstddef>。如果是std::size_t的错,第一个错误将在line 10... -
我也在查看this answer 以获得更多线索。到目前为止还没有运气。
标签: c++ c++11 memory-management heap-memory stack-memory