从矢量继承是否可以? [英] Is it ok to inherit from vector?

查看:96
本文介绍了从矢量继承是否可以?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜欢这个。


/ ******************** /

类卡{

public:

Card():rank(0),suit(0){}

...

私人:

int rank;

int suit;

};


class卡片:公共载体<卡片> {

public:

Cards();

...

};

/ ******************** /


如字符串等其他STL类型呢?


谢谢。

Like this.

/********************/
class Card {
public:
Card() : rank(0), suit(0) {}
...
private:
int rank;
int suit;
};

class Cards : public vector<Card> {
public:
Cards();
...
};
/********************/

What about other STL types like string?

Thanks.

推荐答案

Freddy Flares写道:
Freddy Flares wrote:
喜欢这个。

/ ******************** /
类卡{
公开:
卡():排名(0),西装(0){}
...
私人:
int rank;
int suit;
};

班级卡片:公共向量<卡> {
公开:
卡();
...
};
/ ***************** *** /

其他STL类型如字符串怎么样?
Like this.

/********************/
class Card {
public:
Card() : rank(0), suit(0) {}
...
private:
int rank;
int suit;
};

class Cards : public vector<Card> {
public:
Cards();
...
};
/********************/

What about other STL types like string?




我不会别人会 - 看到线程并制作自己的请注意。
http://groups.google.com/groups?as_u....uni-berlin.de



I wouldn''t others would - see thread and make your own mind up.
http://groups.google.com/groups?as_u....uni-berlin.de


Freddy Flares写道:
Freddy Flares wrote:
喜欢这个。

/ ******************** /
类卡{
公开:
卡():排名(0),西装(0){}
...
私人:
int rank;
int suit;
};

类卡:公共向量<卡> {
公开:
卡();
...
};
/ ***************** *** /

其他STL类型如字符串怎么样?
Like this.

/********************/
class Card {
public:
Card() : rank(0), suit(0) {}
...
private:
int rank;
int suit;
};

class Cards : public vector<Card> {
public:
Cards();
...
};
/********************/

What about other STL types like string?



是的 - 只要用卡片创建的任何矢量都没有问题从卡片的析构函数中摧毁了



除此之外,你会听到其余的是宗教信仰。

G


Yes sure - no problems as long as any vector created with "Cards" is
destroyed from Cards''s destructor.

Apart from this, the rest you''ll hear is religion.

G


>是的 - 只要使用卡片创建的任何矢量都没有问题。是
> Yes sure - no problems as long as any vector created with "Cards" is
从卡片的析构函数中销毁。

除此之外,你会听到的其余部分是宗教信仰。
destroyed from Cards''s destructor.

Apart from this, the rest you''ll hear is religion.



我同意。人们喜欢引用关于缺乏虚拟

析构函数的广告。和混凝土课程(包括Stroustrup本人),但不管纯粹主义者说什么,它都是b $ b bunk(我在田间工作了20年我知道

我在说什么关于)。如果做得好,这不是问题。



I agree. People like to quote ad nauseam about the lack of "virtual
destructors" and "concrete" classes (including Stroustrup himself) but it''s
bunk no matter what the purists say (and with 20 years in the field I know
what I''m talking about). If done properly it''s not a problem.


这篇关于从矢量继承是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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