| re: A Question about inheritance...
"JustSomeGuy" <nope@nottelling.com> wrote...[color=blue]
> I have a few classes...
>
> class a : std::list<baseclass>
> {
> int keya;
> };
>
> class b : std::list<a>
> {
> int keyb;
> };
>
> class c : std::list<b>
> {
> int keyc;
> };
>
>
> I'm trying to figure out at each level the size of the lists...
>
> so if I have:
>
> int main(int argc, char *argv[])
> {
> c x;
>
> cout << "The size of the c class list is " << x.size() << endl;
> cout << "The size of the b class list is " << ???? << endl;
> cout << "The size of the a class list is " << ???? <<< endl;[/color]
I am not really sure what you're trying to print out. Each instance of
class 'c', and 'x' is no exception, contains potentially more than one
object of class 'b'. So, if you have only one 'x', for which 'b' are you
trying to get the list size? Same goes for an instance of class 'b' that
has potentially a whole list of 'a' objects.
Is it the _sum_ of lists for all objects 'b' you're looking to compute?
You probably need to use some combination of 'std::accumulate' and your
own functor that will call '.size' for each object in 'c's list.
Do the same for all objects 'a' in each object 'b': have the functor
that will enumerate all 'a' objects (like the one for 'b's sizes) and
use it on each object 'b'... std::for_each may also be of some help.
[color=blue]
> }
> -------------------------------------------------------------------------[/color]
V |