2011-02-02 168 views
1
//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 

为什么我得到这些错误?

编辑

的问题就解决了。由于

回答

3

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

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

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

代替(注意:dict.begin后括号)

没有编译代码自己我不确定是否还有其他潜在的东西。如果我找到其他东西,我会继续寻找并更新这个答案。

编辑:我注意到,您的seamlessPointer类不标注任何的其成员函数public,这将使任何使用他们的编译时错误。这可能至少是你得到的其他错误的部分原因。

+0

我解决了这个问题。但是还有更多的错误。 – Sean 2011-02-02 05:28:43

2

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