stl容器样式问题 [英] stl containers style issue
问题描述
您好,
我最近因为个人项目而进入STL,我不能确定是否需要b $ b包装容器与否。所以选择是否要像这样成员变量
:
std :: vector< Stuff> m_stuff;
或者将它包装在''StuffVector''类中,将操作封装在
向量上......
>
StuffVector m_stuff;
那里的STL爱好者更喜欢什么?
谢谢。
>
推荐答案
" Glen Able" <再******** @ hoxtmxail.com>在消息中写道
news:bp ******************* @ news.demon.co.uk ...
Hi,
"Glen Able" <re***********************@hoxtmxail.com> wrote in message
news:bp*******************@news.demon.co.uk...
你好,
我最近进入STL进行个人项目,我不能决定是否包装容器。所以选择是否
有一个这样的成员变量:
std :: vector< Stuff> m_stuff;
除非你想使用某些特定于
std:vector< Stuff>的方法,否则我会这样做。 (所以不是通用的算法或标准的矢量方法)然后
将它包装在带有方法的类中是有意义的。
只是我的意见,
问候,Ron AF Greve
或者将它包装在''StuffVector''类中,将操作封装在
向量中......
StuffVector m_stuff;
STL爱好者喜欢什么?
谢谢。
Hello,
I''ve been getting into the STL lately for personal projects and I''m can''t
decide whether to wrap containers or not. So the choice is whether to have a member variable like this:
std::vector<Stuff> m_stuff;
I would go for this, unless you want to use some methods specific for
std:vector<Stuff> (so not generic algoritms or standard vector methods) then
it would make sense to wrap it in a class with the methods.
Just my opinion,
Regards, Ron AF Greve
Or to wrap it in a ''StuffVector'' class, encapsulating operations on the
vector...
StuffVector m_stuff;
What do the STL aficionados out there prefer?
thanks.
< br>
Moonlit写道:
Moonlit wrote:
Glen Able <再******** @ hoxtmxail.com>在消息中写道
新闻:bp ******************* @ news.demon.co.uk ...
Hi,
"Glen Able" <re***********************@hoxtmxail.com> wrote in message
news:bp*******************@news.demon.co.uk...
你好,
我最近因为个人项目而进入STL,我不能决定是否包装容器。所以选择是否
Hello,
I''ve been getting into the STL lately for personal projects and I''m can''t
decide whether to wrap containers or not. So the choice is whether to
有
这样的成员变量:
std :: vector< Stuff> m_stuff;
a member variable like this:
std::vector<Stuff> m_stuff;
我会这样做,除非你想使用某些特定于
std的方法:vector< Stuff> (所以不是通用的算法或标准的矢量方法)
然后用方法将它包装在一个类中是有意义的。
只是我的意见,
问候,Ron AF Greve
I would go for this, unless you want to use some methods specific for
std:vector<Stuff> (so not generic algoritms or standard vector methods)
then it would make sense to wrap it in a class with the methods.
Just my opinion,
Regards, Ron AF Greve
或者将它包装在''StuffVector''类中,将操作封装在
矢量上......
StuffVector m_stuff;
STL爱好者喜欢什么?
谢谢。
Or to wrap it in a ''StuffVector'' class, encapsulating operations on the
vector...
StuffVector m_stuff;
What do the STL aficionados out there prefer?
thanks.
我不是其中一个狂热爱好者,但我喜欢的方式是:
typedef std :: vector< Stuff> StuffVector;
在一般标题中;
在意大利我们说你得到一只带有两个蚕豆的鸽子
i''m not one of the aficionados, but the way i like is:
typedef std::vector<Stuff> StuffVector;
in a general header;
in Italy we say "you get one pigeon with two broad beans"
Glen Able <再******** @ hoxtmxail.com>在留言新闻中写道:< bp ******************* @ news.demon.co.uk> ...
"Glen Able" <re***********************@hoxtmxail.com> wrote in message news:<bp*******************@news.demon.co.uk>...
你好,
我最近因为个人项目而进入STL,我不能决定是否包装容器。所以选择是否有这样的成员变量:
std :: vector< Stuff> m_stuff;
或者将它包装在''StuffVector''类中,将操作封装在
向量中......
StuffVector m_stuff;
那里的STL爱好者更喜欢什么?
Hello,
I''ve been getting into the STL lately for personal projects and I''m can''t
decide whether to wrap containers or not. So the choice is whether to have
a member variable like this:
std::vector<Stuff> m_stuff;
Or to wrap it in a ''StuffVector'' class, encapsulating operations on the
vector...
StuffVector m_stuff;
What do the STL aficionados out there prefer?
我通常将我的选择限制为使用标准库
object直接,
typedef std :: vector< Stuff> StuffBuff;
或包装标准库容器并转发我认为必要的几个
操作。
class StuffBuff
{
public:
void addStuff(const Stuff&);
void removeStuff(const Stuff& );
私人:
typedef std :: vector< Stuff> StuffContainer;
StuffContainer m_stuffContainer;
};
我选择哪个取决于应用程序和我想要的界面
目前。
我一般认为继承是一个有限的
应用程序的有用工具:我使用C ++的时间越长,
类深度大于2或3的层次结构让我印象深刻。我从未发现它需要从标准库对象派生所需的
,呃,
std ::基于异常的类和一些IOStreams类的例外。
我的经验法则说它最好拥有(拥有成员) )而不是
贷款(借用界面)非接口类。
-
Stephen M. Webb
I generally limit my choices to either using the standard library
object directly,
typedef std::vector<Stuff> StuffBuff;
or wrapping the standard library container and forwarding the few
operations I believe necessary.
class StuffBuff
{
public:
void addStuff(const Stuff&);
void removeStuff(const Stuff&);
private:
typedef std::vector<Stuff> StuffContainer;
StuffContainer m_stuffContainer;
};
Which I choose depends on the application and what interface I want to
present.
I have generally found inheritance to be a useful tool of limited
application: the longer I have used C++, the less I am impressed by
class heirarchies of depth greater than 2 or 3. I have never found it
necessary to derive from standard library objects, with the, uh,
exception of std::exception-based classes and some IOStreams classes.
My rule of thumb says it''s better to own (have as a member) than to
loan (borrow the interface of) a non-interface class.
--
Stephen M. Webb
这篇关于stl容器样式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!