当前位置: 代码迷 >> C++ >> 初学者有关问题 关于一个类是另外一个类的元素的构造函数如何写
  详细解决方案

初学者有关问题 关于一个类是另外一个类的元素的构造函数如何写

热度:4291   发布时间:2013-02-26 00:00:00.0
菜鸟问题 关于一个类是另外一个类的元素的构造函数怎么写
  1 #include<iostream>
  2 #include<stdio.h>
  3 using namespace std;
  4 
  5 typedef enum {A=1,B,C,D} SchoolName;
  6 typedef enum {male=1,female} SexType;
  7 typedef enum {run=1,jump} MatchType;
  8 class Component {   //school name  sex match score
  9     private:
 10         SchoolName school;
 11         string name;
 12         SexType sex;
 13         MatchType match;
 14         int score;
 15     public:
 16         Component(SchoolName s_school=D , SexTypes_sex=male ,MatchTypes_match=run, int s_score=0 , char * s_name="zs" )   //②还有这个地方本来想把默认的全搞成0值的不过编译的时候报错了,如 SchoolName s_school=0 ;①号问题在下面
 17         {
 18             school=s_school;
 19             sex=s_sex;
 20             name=s_name;
 21             match=s_match;
 22             score=s_score;
 23         }
 24 };


 29 class ComponentList {
 30     private:
 31         Component clist[128];
 32         int top; //下标
 33 /*      void init()
 34         {
 35             top=0;
 36             int i;
 37             for(i=0;i<128;i++){
 38                 clist[i].school=0;
 39                 clist[i].sex=0;
 40                 clist[i].match=0;
 41                 clist[i].score=0;
 42                 clist[i].name="NULL";
 43             }
 44         }
 45 */
 46     public:
 47 /*      ComponentList()    //我写的构造函数 编译的时候错了也知道为什么错了(component的成员是私有的),可是正确的 还是不会写
  相关解决方案