从STL容器派生 [英] Deriving from STL containers

查看:113
本文介绍了从STL容器派生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI


如果我定义类DoubleMap,那么

struct DoubleMap:public std :: map< std :: string,double> {} ;


调用std :: map成员函数是否有任何开销?

此外是STL容器析构函数虚拟>


N

解决方案

BTW ..我知道我可以做一个typedef


所以让我重新定义DoubleMap以澄清我的问题。


模板< typename键>

struct DoubleMap:public std :: map< Key,双> {};


Nind ... @ yahoo.co.uk写道:


HI


如果我定义DoubleMap类,那么


struct DoubleMap:public std :: map< std :: string,double> {};


调用std :: map成员函数是否有任何开销?

此外是STL容器析构函数虚拟>


N


再次抱歉.....假设我已经投入必要的

构造函数。




模板< typename键>

struct DoubleMap:public std :: map< Key,double> {

DoubleMap():std :: map< Ky,double>(){}


};
Ni ***** @ yahoo.co.uk 写道:


BTW ..我知道我可以做一个typedef


所以让我重新定义DoubleMap来澄清我的问题。


模板< typename键>

struct DoubleMap:public std: :map< Key,double> {};


Nind ... @ yahoo.co.uk写道:


HI


如果我定义DoubleMap类,那么

struct DoubleMap:public std :: map< std :: string,double> {};


调用std :: map成员函数是否有任何开销?

Moreo ver是STL容器析构函数虚拟>


N


Ni ***** @ yahoo.co.uk 写道:


BTW ..我知道我可以做一个typedef


所以让我重新定义DoubleMap以澄清我的问题。


template< typename Key>

struct DoubleMap:public std :: map< Key,double> {};


Nind ... @ yahoo.co.uk写道:



哎呀:(a)请注意,在这个群组中,顶级帖子不赞成所有常客。
$ br />


> HI

如果我定义类DoubleMap,那么

struct DoubleMap:public std :: map< std :: string,double> {};

调用std :: map成员函数有什么开销吗?



No.


>此外是STL容器析构函数虚拟>



No.这意味着你不应该使用指向STL容器的指针

多态。


另请注意,当您拥有带签名的
函数时,公共继承可以产生有趣的结果

STL_container< Tdo_something(STL_container< Tconst&);


在这种情况下,你的派生类会匹配,但返回类型将是

可能不是你所期望的。请注意,私有继承不会涉及任何这种棘手的问题。


> >
N



哎呀:另外:请不要引用签名。


Best


Kai-Uwe Bux


HI

If I define the class DoubleMap such that
struct DoubleMap : public std::map<std::string, double>{};

Is there any overhead in calling std::map member functions ?
Moreover are STL containers destructors virtual >

N

解决方案

BTW .. I know I can do a typedef

so let me re-define DoubleMap to clarify my question .

template<typename Key>
struct DoubleMap : public std::map<Key, double>{};

Nind...@yahoo.co.uk wrote:

HI

If I define the class DoubleMap such that
struct DoubleMap : public std::map<std::string, double>{};

Is there any overhead in calling std::map member functions ?
Moreover are STL containers destructors virtual >

N


again sorry ..... lets suppose I have put in the necessary
constructors.
the is

template<typename Key>
struct DoubleMap : public std::map<Key, double>{
DoubleMap():std::map<Ky,double>(){}

};
Ni*****@yahoo.co.uk wrote:

BTW .. I know I can do a typedef

so let me re-define DoubleMap to clarify my question .

template<typename Key>
struct DoubleMap : public std::map<Key, double>{};

Nind...@yahoo.co.uk wrote:

HI

If I define the class DoubleMap such that
struct DoubleMap : public std::map<std::string, double>{};

Is there any overhead in calling std::map member functions ?
Moreover are STL containers destructors virtual >

N


Ni*****@yahoo.co.uk wrote:

BTW .. I know I can do a typedef

so let me re-define DoubleMap to clarify my question .

template<typename Key>
struct DoubleMap : public std::map<Key, double>{};

Nind...@yahoo.co.uk wrote:

Oops: (a) please note that top-posting is frowned upon in this group by
virtually all regulars.

>HI

If I define the class DoubleMap such that
struct DoubleMap : public std::map<std::string, double>{};

Is there any overhead in calling std::map member functions ?

No.

>Moreover are STL containers destructors virtual >

No. That means you should not use pointers to STL containers
polymorphically.

Also note that public inheritance can yield funny results when you have
functions with signature

STL_container<Tdo_something ( STL_container<Tconst & );

In this case, your derived classes will match, but the return type will
probably not be what you expect. Note that private inheritance does not
involve any of this trickyness.

>>
N

Oops: Also: please do not quote signatures.

Best

Kai-Uwe Bux


这篇关于从STL容器派生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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