问题描述
在《C++ Primer》的13.5节的动态内存管理类中,一旦将allocator设为静态成员,编译时就会报错。
class StrVec{ /* other code */ private: static allocator<string> alloc;}
错误原因在下面
操作系统window10,书上的代码是有static的。为什么会这样的?谢谢。
问题解答
回答1:类里的static成员只是声明,还要在类外进行定义。
在某个cpp文件里加上:
allocator<string> StrVec::alloc;

