求助:对构造函数和对象成员的迷茫,大家帮忙看下是如何调用的
#include <iostream.h>class object {
private:
int val;
public:
object();
object(int i);
~object();
};
object::object()
{
val=0;
cout << "Default constructor for object" << endl;
}
object::object(int i)
{
val = i;
cout << "Constructor for object " << val <<endl;
}
object::~object()
{
cout << "Destructor for object "<< val << endl;
}
class container {
privat:
object one;
object two; //object的两个对象one和two定义到container中和定义在类外是不是一样的含义?
int data;
public:
container();
container(int i, int j , int k);
~container();
};
container:: container()
{
data = 0;
cout << "Default constructor for oontainer " endl ;
}
containe::container(int i, int j , int k):two(i),one(j) //该构造函数该如何理解?
{
data = k;
cout << "Constructor for container " << endl;
}
container::~container()
{
cout << "Destructor for container " << endl;
}
main()
{
container anObj( 5 , 6 ,10);
}
下面的这个构造函数一直不是很明白是如何进行调用的:
containe::container(int i, int j , int k):two(i),one(j)
{
data = k;
cout << "Constructor for container " << endl;
}
麻烦大家给解释下了 非常感谢
有构造函数对象成员资料的也可以发下 先谢谢了