大神不要不鸟我啊,构造函数不懂了
#include "stdafx.h"#include<iostream>
using namespace std;
class Base
{
int i;
public:
Base(int n)
{
cout<<"constructing Base class\n";
i=n;
}
~Base()
{
cout<<"destructing Base class\n";
}
void showi()
{
cout<<i<<endl;
}
};
class Derived:public Base
{
int j;
Base ob;
public:
Derived(int n):Base(n),ob(n)
{
cout<<"constrycting Derived class"<<endl;
j=2*n;
}
~Derived()
{
cout<<"destructing Derived class"<<endl;
}
void showj()
{
cout<<j<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Derived ob(10);
ob.showi();
ob.showj();
return 0;
}
这个main里ob的i是从哪里来的?派生类构造函数的Base么?话说派生的成员里还有个基类对象ob里也有个i么,在哪里赋值呢,小白求教,大神不要不鸟我,谢谢