嵌套迭代器错误

时间:2011-02-02 05:08:55

标签: c++ iterator

//arrayList.h
template<class T>
class arrayList{
public:
    // constructor, copy constructor and destructor
    arrayList(int initialCapacity = 10);
    arrayList(const arrayList<T>&);
    ~arrayList();
    // iterators to start and end of list
    class iterator;
    class seamlessPointer;
    seamlessPointer begin();
    seamlessPointer end() ;
    protected:
        T* position;
    }; // end of iterator class

protected:
    T* element;
    int arrayLength; 
    int listSize; 
};


//main.cpp


int main() {

...........

    sort(dict.begin, dict.end(),compare_nocase); ////
    return 0;
}

有两个错误:

..\src\test.cpp: In function 'int main()':
..\src\test.cpp:50:44: error: no matching function for call to 'sort(<unresolved overloaded function type>, arrayList<std::basic_string<char> >::seamlessPointer, bool (&)(std::string, std::string))'

..\src\/arrayList.h: In member function 'arrayList<T>::seamlessPointer arrayList<T>::end() [with T = std::basic_string<char>]':
..\src\test.cpp:50:28:   instantiated from here
..\src\/arrayList.h:114:3: error: 'arrayList<T>::seamlessPointer::seamlessPointer(T*) [with T = std::basic_string<char>]' is private
..\src\/arrayList.h:49:44: error: within this context

为什么我会收到这些错误?

修改

问题解决了。感谢

2 个答案:

答案 0 :(得分:3)

我认为其中一个问题是你写过

sort(dict.begin, dict.end(),compare_nocase);

而不是

sort(dict.begin(), dict.end(),compare_nocase);

(注意dict.begin之后的括号)

如果不自行编译代码,我不确定这里是否还有其他东西。如果我发现其他任何问题,我会一直关注并更新这个答案。

编辑: 我注意到您的seamlessPointer类没有标记任何成员函数public,它们可以使用他们是一个编译时错误。这可能至少部分地导致了你得到的其他错误。

答案 1 :(得分:2)

对于第二个错误,看起来你刚刚从seamlessPointer类中省略了public:访问说明符。请记住,C ++中的类成员默认是私有的,因此其代码的其余部分都不能访问它的构造函数或成员函数。