大佬教程收集整理的这篇文章主要介绍了c – 扩展std :: list,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的代码如下所示:
#include <list> template <class T > class myList : public std::list<T> { public: T operator[](int indeX); T operator[](int & indeX); myList(void); ~myList(void); }; #include "myList.h" template<class T> myList<T>::myList(void): std::list<T>() {} template<class T> myList<T>::~myList(void) { std::list<T>::~list(); } template<class T> T myList<T>::operator[](int indeX) { int count = 0; std::list<T>::iterator itr = this->begin(); while(count != indeX)itr++; return *itr; } template<class T> T myList<T>::operator[](int & indeX) { int count = 0; std::list<T>::iterator itr = this->begin(); while(count != indeX)itr++; return *itr; }
您的代码有问题,如果用户请求负数或太大(超过列表中的元素数量)会怎样.而且我看起来并不太多.
此外,我不知道你打算如何使用它,但你的运算符[]是O(N)时间,这可能很容易导致O(N * N)循环……
以上是大佬教程为你收集整理的c – 扩展std :: list全部内容,希望文章能够帮你解决c – 扩展std :: list所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。