C++ 尝试打印对象列表的向量时出错?

C++ 尝试打印对象列表的向量时出错?,c++,list,vector,iterator,hashtable,C++,List,Vector,Iterator,Hashtable,所以我试着用下面的代码打印出一个哈希表中对象列表的向量,但我一直收到这些错误,我不知道为什么 SeparateChaining.h: In member function 'void HashTable<HashedObj>::print()': SeparateChaining.h:165:13: error: need 'typename' before 'std::list<HashedObj>::iterator' because 'std::list<Ha

所以我试着用下面的代码打印出一个哈希表中对象列表的向量,但我一直收到这些错误,我不知道为什么

SeparateChaining.h: In member function 'void HashTable<HashedObj>::print()':
SeparateChaining.h:165:13: error: need 'typename' before 'std::list<HashedObj>::iterator' because 'std::list<HashedObj>' is a dependent scope
SeparateChaining.h:165:39: error: expected ';' before 'li'
SeparateChaining.h:166:17: error: 'li' was not declared in this scope
SeparateChaining.h: In instantiation of 'void HashTable<HashedObj>::print() [with HashedObj = Symbol]':
Driver.cpp:72:21:   required from here
SeparateChaining.h:165:13: error: dependent-name 'std::list<HashedObj>::iterator' is parsed as a non-type, but instantiation yields a type
SeparateChaining.h:165:13: note: say 'typename std::list<HashedObj>::iterator' if a type is meant
SeparateChaining.h:在成员函数“void HashTable::print()”中:
SeparateChaining.h:165:13:错误:需要在“std::list::iterator”之前加上“typename”,因为“std::list”是一个依赖作用域
SeparateCaching.h:165:39:错误:应为“;”在‘李’之前
SeparateChaining.h:166:17:错误:“li”未在此范围内声明
SeparateChaining.h:在“void HashTable::print()[带HashedObj=Symbol]”的实例化中:
Driver.cpp:72:21:从这里开始需要
SeparateChaining.h:165:13:错误:依赖名称“std::list::iterator”被解析为非类型,但实例化会生成一个类型
SeparateChaining.h:165:13:注意:如果表示类型,请说“typename std::list::iterator”
下面是我的类的一个片段,它具有打印功能:

class HashTable
{

    /// ....



        void print()
        {

            for(int i = 0; i < theLists.size(); ++i)
            {
                list<HashedObj>::iterator li;
                for(li = theLists[i].begin(); li != theLists[i].end(); ++li)
                    cout << "PLEASE WORK" << endl;
            }
    /*
            for(auto iterator = oldLists.begin(); iterator!=oldLists.end(); ++iterator) 
                for(auto itr = theLists.begin(); itr!=theLists.end(); ++itr)
                    cout << *itr << endl;
    */
        }

      private: 
         vector<list<HashedObj>> theLists;   // The array of Lists

};
类哈希表
{
/// ....
作废打印()
{
对于(int i=0;icout如果你仔细阅读错误,它会说这行:

list<HashedObj>::iterator li;
list::迭代器li;
应改为:

typename list<HashedObj>::iterator li;
typename列表::迭代器li;
基本上,您需要告诉编译器您正在处理一个类型。有关正在进行的操作的更多详细信息,请参阅或

您可能有其他错误,但需要首先解决这些错误

SeparateChaining.h:165:13: error: need 'typename' before 'std::list<HashedObj>::iterator' because 'std::list<HashedObj>' is a dependent scope

查看

你能展示整个类吗?或者你能像编译器所说的那样先在list::iterator之前添加typename吗?
SeparateChaining.h:165:13: error: need 'typename' before 'std::list<HashedObj>::iterator' because 'std::list<HashedObj>' is a dependent scope
typename list<HashedObj>::iterator li;