gpt4 book ai didi

c++ - 静态函数调用错误 "C++ requires a type specifier for all declarations"

转载 作者:行者123 更新时间:2023-11-28 00:38:19 26 4
gpt4 key购买 nike

我的分配器有一个静态内存池:

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 --------------------------------^^

关于c++ - 静态函数调用错误 "C++ requires a type specifier for all declarations",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20053216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com