A Question about inheritance...

J

JustSomeGuy

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.
 
V

Victor Bazarov

JustSomeGuy said:
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;

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.
}
-------------------------------------------------------------------------

V
 
J

JustSomeGuy

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.

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top