在这个类中定义这三个是否有任何意义? 不应该是对象列表,复制名称和大小并且 自动销毁?I have a classclass myImage: public std::list<myObject>{private: std::string myImageName; unsigned long size;public: myImage(void); myImage & operator=(const myImage &i); myImage(const myImage &i); ~myImage(void); // There is no public data. // A bunch of methods...};My question is:as there is no use of ''new'' is there anything that needs be done intheassignment operator, copy constructor and destructor?specifically... the std::list<myObjectthat this class is derivingfrom...Is there any point in defining these three in this class?Shouldn''t the list of objects, the name and size be copied anddestroyed automatically? 是的,列表将被销毁并正确分配,你不需要担心这个问题。但是,你确定要从 std :: list派生吗?这看起来有点奇怪,因为概念上图像 不是对象列表。考虑一个std :: list成员,如果你没有实际上需要一个列表界面,以便改善信息隐藏。 另外,尺寸与列表的大小不一样,是吗? 问候, Zeppeyes, the list will be destroyed and allocated properly, you needn''tworry about that. However, are you sure that you want to derive fromstd::list? It seems a little bit strange, because conceptually an imageis not a list of object. Consider a std::list member if you don''tactually need a list interface, in order to improve the information hiding.Also, the size is not the same as the size of the list, is it?Regards,Zeppe 6月13日上午11:09,Zeppe < zep_p @ .remove.all.this.long.comment.yahoo.itwrote:On Jun 13, 11:09 am, Zeppe<[email protected] : SpreadTooThin写道:SpreadTooThin wrote: 我有一个类 class myImage:public std :: list< myObject> { private: std :: string myImageName; unsigned long size; public: myImage(void); myImage& operator =(const myImage& i); myImage(const myImage& i); ~myImage(void); I have a class class myImage: public std::list<myObject> { private: std::string myImageName; unsigned long size; public: myImage(void); myImage & operator=(const myImage &i); myImage(const myImage &i); ~myImage(void); //没有公开数据。 //一堆方法...... }; // There is no public data. // A bunch of methods... }; 我的问题是: My question is: 因为没有使用''new''有什么需要在 赋值运算符,复制构造函数和析构函数中完成吗? 具体...... std :: list< myObject这个类派生的是...... b $ b来自... as there is no use of ''new'' is there anything that needs be done in the assignment operator, copy constructor and destructor? specifically... the std::list<myObjectthat this class is deriving from... 定义这些是否有任何意义本课程中有三个? 难道不是对象列表,名称和大小被复制并且 会自动销毁吗? Is there any point in defining these three in this class? Shouldn''t the list of objects, the name and size be copied and destroyed automatically? 是的,列表将被销毁并正确分配,你不必担心担心。但是,你确定要从 std :: list派生吗?这看起来有点奇怪,因为概念上图像 不是对象列表。考虑一个std :: list成员,如果你没有实际上需要一个列表界面,以便改善信息隐藏。 另外,大小与列表的大小不一样,是吗? 问候, Zeppeyes, the list will be destroyed and allocated properly, you needn''tworry about that. However, are you sure that you want to derive fromstd::list? It seems a little bit strange, because conceptually an imageis not a list of object. Consider a std::list member if you don''tactually need a list interface, in order to improve the information hiding.Also, the size is not the same as the size of the list, is it?Regards,Zeppe 嗯,在这个例子中它有点像是一个对象列表..它就像一个tiff 文件。 和ya我认为你的权利吧将 列表存储为私有变量列表可能更好。Well in this instance it kinda is a list of objects.. Its like a tifffile.and ya I think your right it probably is a better idea to stash thelist as a private memeber variable. 这篇关于关于三个规则的问题....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-10 23:55