C++ 类中的映射给出编译错误

C++ 类中的映射给出编译错误,c++,visual-c++,c++11,visual-studio-2012,C++,Visual C++,C++11,Visual Studio 2012,我试图定义一个类 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: sy

我试图定义一个类

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  

我试着把地图改成一些简单的东西,比如地图节点,但它仍然会给我同样的错误。我遗漏了什么吗?

这可能是因为您没有在使用中列出std名称空间。类型映射不在全局命名空间中,因此映射不可解析。试试下面的方法

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

  ...
};

这可能是因为您没有在using中列出std名称空间。类型映射不在全局命名空间中,因此映射不可解析。试试下面的方法

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

  ...
};

我必须等11分钟才能把你的答案标记为被接受,我将用我的头撞在墙上:/。谢谢,我得等11分钟才能把你的答案标记为接受,我将用头撞墙的方式来回答:/。thankstypename不能在模板声明之外使用。。。嗯。。代码中没有typename,您确定要同时提供代码和错误吗?typename不能在模板声明之外使用。。。嗯。。代码中没有typename,您确定要同时提供代码和错误吗?