课堂上的地图给出编译错误

map in class gives compile error

本文关键字:编译 错误 地图 课堂      更新时间:2023-10-16

我正在尝试定义类

class BTree
{
private:
     map<std::string,BTree*> *node;
public:
    BTree(void);
    ~BTree(void);
    void Insert(BTree *);
};

编译代码时,编译器给我一个错误

error C2899: typename cannot be used outside a template declaration  
error C2143: syntax error : missing ';' before '<'  
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  
error C2238: unexpected token(s) preceding ';'  
error C2899: typename cannot be used outside a template declaration  

我试图将地图更改为简单的诸如map<int,int> node之类的东西,它仍然给我带来相同的错误。我想念什么吗?

这可能是因为您没有using中列出的std名称空间。map类型不在全局名称空间中,因此map无法解析。尝试以下

class BTree {
private:
  std::map<std::string, BTree*> *node;
  ...
};