关于三个规则的问题.... [英] A question about the rule of three....

查看:45
本文介绍了关于三个规则的问题....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个班级

班级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);


//没有公开数据。

//一堆方法......

};


我的问题是:


因为没有使用''new''有什么需要在



赋值运算符,复制构造函数和析构函数?

具体...... std :: list< myObject这个类派生的是来自...



在这个类中定义这三个是否有任何意义?

不应该是对象列表,复制名称和大小并且

自动销毁?

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:

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?

推荐答案

6月13日17:27,SpreadTooThin< bjob​​rie ... @ gmail.comwrote:
On 13 Jun, 17:27, SpreadTooThin <bjobrie...@gmail.comwrote:

我有一个类

class myImage:public std :: list< myObject>

{

私人:

std :: string myImageName;

unsigned long size;

public:

myImage(void);

myImage& operator =(const myImage& i);

myImage(const myImage& i);

~myImage(void);


//没有公开数据。

//一堆方法......


};


我的问题是:


因为没有使用''new''有什么需要在

中完成的吗? />
赋值运算符,复制构造函数和析构函数?

具体...... std :: list< myObject这个类派生来自...
来自...
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:

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...



你应该知道是否需要其他东西

,因为你是设计这个课程的人。


如果你写了

class myImage:public std :: list< myObject>

{

private:

std :: string myImageName;

unsigned long size;

};


编译器将生成默认值构造函数,

复制构造函数,赋值运算符和

de structor。所有你想做的事情

他们这样做。


默认构造函数将调用默认构造函数

的基数和成员,复制构造函数

将调用基础的复制构造函数和

成员等...

you should know whether something else needs to be
done since you''re the one who designed this class.

if you write
class myImage: public std::list<myObject>
{
private:
std::string myImageName;
unsigned long size;
};

compiler will generate default constructor,
copy constructor, assignment operator and
destructor. all doing what you would expect
them to do.

default constructor will call default constructor
of the base and members, copy constructor
will call copy constructors of the base and of
the members, etc...


在这个课程中定义这三个是否有任何意义?
Is there any point in defining these three in this class?



除非编译器生成的不足够。

not unless compiler generated ones are not sufficient.


不应该是对象列表,要复制名称和大小并自动销毁

Shouldn''t the list of objects, the name and size be copied and
destroyed automatically?



当然。


DS

Of course.

DS


SpreadTooThin写道:
SpreadTooThin wrote:

我有一个类

类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);


//没有公开数据。

//一堆方法......

};


我的问题是:


因为没有使用''new''有什么需要在



赋值运算符,复制构造函数和析构函数?

具体...... std :: list< myObject这个类派生的是来自...



在这个类中定义这三个是否有任何意义?

不应该是对象列表,复制名称和大小并且

自动销毁?
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:

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成员,如果你没有
实际上需要一个列表界面,以便改善信息隐藏。


另外,尺寸与列表的大小不一样,是吗?


问候,


Zeppe

yes, the list will be destroyed and allocated properly, you needn''t
worry about that. However, are you sure that you want to derive from
std::list? It seems a little bit strange, because conceptually an image
is not a list of object. Consider a std::list member if you don''t
actually 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
<zep_p@.remove.all.this.long.comment.yahoo.itwrote :

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成员,如果你没有
实际上需要一个列表界面,以便改善信息隐藏。


另外,大小与列表的大小不一样,是吗?


问候,


Zeppe


yes, the list will be destroyed and allocated properly, you needn''t
worry about that. However, are you sure that you want to derive from
std::list? It seems a little bit strange, because conceptually an image
is not a list of object. Consider a std::list member if you don''t
actually 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 tiff
file.
and ya I think your right it probably is a better idea to stash the
list as a private memeber variable.


这篇关于关于三个规则的问题....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆