本文介绍了一个简单的c ++问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几节课...


a类:std :: list< baseclass>

{

int keya;

};


class b:std :: list< a>

{

int keyb;

};


class c:std :: list< b>

{

int keyc;

};

我想在每个级别弄清楚列表的大小......


如果我有:


int main(int argc,char * argv [])

{

cx;


cout<< c类列表的大小是 << x.size()<< endl;

cout<< b类列表的大小是 << ???? << endl;

cout<< 班级列表的大小是 << ???? <<< endl;

}

------------------------------- ------------------------------------------


想一想......

使用std :: list的继承可能不是最好的想法..

或许:


类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;

};


可能是一个更好的实现,但问题仍然存在。

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.

推荐答案




耐心是一种美德/>



Patience is a virtue





这篇关于一个简单的c ++问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:27