我有一个用于分配器的静态内存池:
template<typename Tag>
struct AllocatorPool {
static void initialize(size_t bytes)
{
gPool.allocatePool(bytes);
}
typedef AllocatorImpl::Pool tPool;
static tPool gPool;
};
内存池的定义:
template<typename T> typename AllocatorPool<T>::tPool AllocatorPool<T>gPool;
如果我想像这样初始化池:
AllocatorPool<MyClass>::initialize(1024);
编译器为此行输出以下错误:
"C++ requires a type specifier for all declarations"
我使用Xcode 4.6.3和Apple LLVM编译器4.2
最佳答案
尝试改变
template<typename T> typename AllocatorPool<T>::tPool AllocatorPool<T>gPool;
至
template<typename T> typename AllocatorPool<T>::tPool AllocatorPool<T>::gPool;
// note the scope resolution operator --------------------------------^^