Connecting Tech Pros Worldwide Help | Site Map

A Question about inheritance...

  #1  
Old July 22nd, 2005, 05:37 PM
JustSomeGuy
Guest
 
Posts: n/a
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;
}
-------------------------------------------------------------------------

Thinking about it...
Using inheritance of std::list may not have been the best idea..
perhaps:

class a : std::list<baseclass>
{
int keya;
std::list<sometype> baseclasslist;
};

class b
{
int keyb;
std::list<a> alist;
};

class c
{
int keyc;
std::list<b> blist;
};

May have been a better implementation, but the question remains.


  #2  
Old July 22nd, 2005, 05:37 PM
Victor Bazarov
Guest
 
Posts: n/a

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


  #3  
Old July 22nd, 2005, 05:37 PM
JustSomeGuy
Guest
 
Posts: n/a

re: A Question about inheritance...


>[color=blue]
> 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.
>[/color]

Yes this dawned on my finally...
I think I need to itterate through each list starting with C then B then A.

Citer->Biter.size(); // might be what I should do (According to another
poster)


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about inheritance vineoff answers 4 October 26th, 2005 09:55 PM
Q question about inheritance Tony Johansson answers 2 July 23rd, 2005 05:40 AM
A question about inheritance arserlom@gmail.com answers 3 July 19th, 2005 02:16 AM
Stylistic question about inheritance Andrew Koenig answers 17 July 19th, 2005 12:19 AM