Re: STL string inheritance
From: David Hilsee (davidhilseenews_at_yahoo.com)
Date: 10/03/04
- Next message: John Harrison: "Re: DATETIME like YYYYMMDDHHMMSS"
- Previous message: Jazzhouse: "DATETIME like YYYYMMDDHHMMSS"
- In reply to: Mike Tyka: "Re: STL string inheritance"
- Next in thread: Daniel T.: "Re: STL string inheritance"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 3 Oct 2004 11:23:00 -0400
"Mike Tyka" <m.tyka@gnx.net> wrote in message news:I50E4K.GFG@bath.ac.uk...
<snip>
> Thanks a lot for all your answers, i think i'm slowly getting my head
round
> this stuff.. I kept the example generic for simplicity's sake.
> I want to create a data structure and a correcponding mask data structure,
> both of
> which have all of the properties of a string, and it would be useful to
have
> all it's functionality
> (like cutting, concatenating etc etc). At the same time both data
structures
> will want to have
> additional functionality, specialised to the type of data they're holding,
> but no more additional
> data - so the lack of virtual destructors etc shouldnt matter !?Hence the
> inherited approach seems
> sensible in this case ?
>
> Am i thinking along the right lines here ?
Even if the derived class contains no additional data, it's still undefined
behavior if you pass delete a std::string pointer when it is a pointer to an
instance of the derived class. Of course, you can avoid doing that in your
programs, and it's hard to accidentally do it simply because std::string has
no virtual member functions.
I tend to gripe about public inheritance of standard containers because it
is using inheritance to expose an implementation detail as a "nameless
public member". Many people choose to do that instead of having a public
member because inheritance is generally considered "better" than public
members. Unfortunately, in this case, it's roughly the same thing. It's a
general problem when inheritance is used for code reuse purposes (discussed
in the FAQ a bit in the Smalltalk/C++ comparison -- 30.4). However, for
most smaller programs, it doesn't really matter.
-- David Hilsee
- Next message: John Harrison: "Re: DATETIME like YYYYMMDDHHMMSS"
- Previous message: Jazzhouse: "DATETIME like YYYYMMDDHHMMSS"
- In reply to: Mike Tyka: "Re: STL string inheritance"
- Next in thread: Daniel T.: "Re: STL string inheritance"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|