473,842 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deriving from STL containers

HI

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

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

N

Nov 10 '06 #1
15 4104
BTW .. I know I can do a typedef

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

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

Nind...@yahoo.c o.uk wrote:
HI

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

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

N
Nov 10 '06 #2
again sorry ..... lets suppose I have put in the necessary
constructors.
the is

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

};
Ni*****@yahoo.c o.uk wrote:
BTW .. I know I can do a typedef

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

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

Nind...@yahoo.c o.uk wrote:
HI

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

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

N
Nov 10 '06 #3
Ni*****@yahoo.c o.uk wrote:
BTW .. I know I can do a typedef

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

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

Nind...@yahoo.c o.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::s tring, 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<T do_something ( STL_container<T const & );

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
Nov 10 '06 #4
Kai-Uwe Bux wrote:
>Nind...@yahoo. co.uk wrote:
>>Moreover are STL containers destructors virtual >

No. That means you should not use pointers to STL containers
polymorphically .
I think you wanted to say "you should not *delete* pointers to your
classes through pointers to STL containers from which your classes
derive". Standard containers don't have virtual functions (AFAICR),
so using them polimorphically is kind of impossible.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 10 '06 #5
sorry am a newbie .. what is top-posting and did I do it ?

Kai-Uwe Bux wrote:
Ni*****@yahoo.c o.uk wrote:
BTW .. I know I can do a typedef

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

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

Nind...@yahoo.c o.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::s tring, 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<T do_something ( STL_container<T const & );

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
Nov 10 '06 #6
Ni*****@yahoo.c o.uk wrote:
sorry am a newbie .. what is top-posting and did I do it ?
You did again! ;)

top-post is when you post your reply on top of the sender's text. I put
my reply below your text, and that's the way it should be. We can then
read it in the same order it was posted.

cheers,
--renato

--
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm
Nov 10 '06 #7

Renato Golin wrote:
Ni*****@yahoo.c o.uk wrote:
sorry am a newbie .. what is top-posting and did I do it ?

You did again! ;)

top-post is when you post your reply on top of the sender's text. I put
my reply below your text, and that's the way it should be. We can then
read it in the same order it was posted.

cheers,
--renato

--
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm

Oh I see .. so this correct right ?

Nov 10 '06 #8
Ni*****@yahoo.c o.uk wrote:
Renato Golin wrote:
>top-post is when you post your reply on top of the sender's text. I put
my reply below your text, and that's the way it should be. We can then
read it in the same order it was posted.

Oh I see .. so this correct right ?
Almost... ;)

It's also a good practice to delete the sender's signature so your reply
goes exactly below my text, as in questions and answers. See how I
trimmed the text up there? Some would even remove my text and let only
the line you wrote, but that can also affect the logic flow.

With multiple questions post every answer below the right question.

cheers,
--renato

--
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm
Nov 10 '06 #9
Victor Bazarov wrote:
Kai-Uwe Bux wrote:
>>Nind...@yahoo .co.uk wrote:
Moreover are STL containers destructors virtual >

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

I think you wanted to say "you should not *delete* pointers to your
classes through pointers to STL containers from which your classes
derive".
Yes, thanks.
Standard containers don't have virtual functions (AFAICR),
so using them polimorphically is kind of impossible.
I was using the phrase "to use polymorphically " more loosely. To me, the
very fact that a B* may have a different dynamic type qualifies as
polymorphic use. I don't know whether there is some standard terminology
that settles this language issue. However, the wording you proposed is
definitely less ambiguous.
Best

Kai-Uwe Bux
Nov 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
4115
by: Steven T. Hatton | last post by:
This may be another question having an obvious answer, but I'm not seeing it. I'm trying to create a class that derives from std::valarray<std::string>. I don't need a template, and I haven't come across any examples of a construct like what I show below. Perhapes it's simply a bad idea. If there is something fundamentally wrong with this approach please let me know. Can anybody tell me if there is a way to get the following to work? I...
8
2851
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl list class must Ioverride in order for this to work?
3
3459
by: | last post by:
I can not seem to get this to compile with either gcc 3.4 or MSVC++ .NET 2003... (source follows first): ---= BEGIN MyStreamBuffer.h =--- // #IFDEF redundancy left out. #include <streambuf> template< class MyElem > class MyStreamBuffer : public std::basic_streambuf< MyElem > { protected:
6
474
by: Adrian | last post by:
Lint (rightly I believe) complains that deque's destructor is not virtual. So will the following code cause any problems? If I do not derive from Container does that stop problems? Do I manually have to call deque's destructor from Containers to make sure? Adrian
7
3796
by: wangxiaohu | last post by:
I am trying to write a class myVector based on std::vector and add only a sort method. The sort method needs to access the array stored in the base class using iterator. I have following draft code. However it never compile. Can anyone take a look and tell me how to fix it? Thanks! #include <vector> #include <iostream> using namespace std;
17
3197
by: mosfet | last post by:
Could someone tell me why it's considered as bad practice to inherit from STL container ? And when you want to customize a STL container, do you mean I need to write tons of code just to avoid to derive from it ?
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9454
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5697
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4090
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.