Connecting Tech Pros Worldwide Help | Site Map

A Question about inheritance...

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 04:37 PM
JustSomeGuy
Guest
 
Posts: n/a
Default A Question about inheritance...

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, 04:37 PM
Victor Bazarov
Guest
 
Posts: n/a
Default 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, 04:37 PM
JustSomeGuy
Guest
 
Posts: n/a
Default 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)


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.