Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么';s类SUP与c+中SUP中定义的类SUP之间的关系+;?_C++_Class_Iterator - Fatal编程技术网

C++ 什么';s类SUP与c+中SUP中定义的类SUP之间的关系+;?

C++ 什么';s类SUP与c+中SUP中定义的类SUP之间的关系+;?,c++,class,iterator,C++,Class,Iterator,我想编写一个名为my_list的容器: template<typename T> class my_list { public: // ... class iterator { private: node* it; } private: struct node { T item; node* next

我想编写一个名为
my_list
的容器:

template<typename T>
class my_list {
    public:
        // ...

        class iterator {
            private:
                node* it;
        }
    private:
        struct node {
            T item;
            node* next;
        }

        node* head;
        node* end;
        int count;
}
模板
给我的清单分类{
公众:
// ...
类迭代器{
私人:
节点*it;
}
私人:
结构节点{
T项;
节点*下一步;
}
节点*头;
节点*结束;
整数计数;
}

但是,类
迭代器
不能使用类my_列表中的私有数据成员。我查阅了一些C++书籍,但没有发现任何东西。

继续阅读并阅读关于朋友类的用法。迭代器是正确使用这种语言特性的典型例子


顺便问一下,您不使用STL数据结构而不使用自己的数据结构有什么原因吗?请参阅。

继续阅读本文中朋友类的用法。迭代器是正确使用这种语言特性的典型例子


顺便问一下,您不使用STL数据结构而不使用自己的数据结构有什么原因吗?请参阅。

您只需要知道节点的结构,而不需要成为列表的朋友。事实上,应该编写迭代器,这样我们就不需要使用友元关系(在大多数标准容器中,这是可能的),您只需要知道节点的结构,而不需要成为列表的友元。事实上,应该编写迭代器,这样我们就不需要使用朋友关系(在大多数标准容器中,这是可能的),除非这是家庭作业或为了学习,更喜欢
std::list
。它已经被编写、调试和优化,并且有很高的文档记录。除非这是家庭作业或是为了学习,最好选择
std::list
。它已经被编写、调试和优化,并且有大量的文档记录。