刚学 组合类的构造函数。Whole :: Print 函数成员中的最后三个 cout 报错
[b][b]#include <iostream.h>const int i = 0;
class Part
{
public :
Part (int x);
void Print ();
private :
int Partval;
};
class Whole
{
public :
Whole (int i,int j,int k);
void Print ();
private :
Part one;
Part two;
Part three;
int date1;
int date2;
int date3;
};
Part :: Part (int x)
{
Partval = x;
cout << " Part 类的私有成员 Partval 构造完成 ; Partval = " << Partval << endl << endl;
}
Whole :: Whole (int i,int j,int k) : one (i),two (j),three (k)
{
date1 = i;
date2 = j;
date3 = k;
}
void main()
{
Part PartA (1);
Whole WholeB (2,3,4);
PartA.Print ();
WholeB.Print ();
}
void Part :: Print ()
{
cout << "Partval = " << Partval << endl << endl;
}
void Whole :: Print ()
{
cout << " Whole 类的私有成员 date1 date2 date3 分别构造完成;" << endl;
cout << "date1 = " << date1 << " ";
cout << "date2 = " << date2 << " ";
cout << "date3 = " << date3 << endl << endl;
cout << "同时 Part 类成员 ont two date 也构造完成" << endl;
cout << "Partone = " << one << " ";
cout << "Parttwo = " << two << " ";
cout << "Parthree = " << three << endl;
}
如果将最后三个 cout 随便输出个别的什么,代码就通过了。比如 cout << "sdf" << endl; 但是写这三个就不行,刚学 组合类构造函数,请大家帮帮小弟。