且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在模板类中定义迭代器时的STL编译错误

更新时间:2022-03-18 09:23:25

您需要 typename std :: list< T> :: iterator 。这是因为 list 取决于模板参数,因此编译器不能知道它的名称迭代器 (很好,从技术上它可以知道,但C ++标准不工作这种方式)。关键字 typename 告诉编译器以下是类型的名称。

You need typename std::list<T>::iterator. This is because list depends on the template parameter, so the compiler cannot know what exactly is the name iterator within it going to be (well, technically it could know, but the C++ standard doesn't work that way). The keyword typename tells the compiler that what follows is a name of a type.