在recorer类中定义了student类,在创建recorder类时,值调用了recorder的构造函数
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
class Recorder
{
class Student
{
public:
Student()
{
cout<<"this is student function"<<endl;
}
};
public:
Recorder()
{
cout<<"this is recorder function"<<endl;
}
};
int main()
{
Recorder t;
return 0;
}
此时,recorder类中有Student类的对象s成员
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
class Student
{
public:
Student()
{
cout<<"this is student function"<<endl;
}
};
class Recorder
{
public:
Recorder()
{
cout<<"this is recorder function"<<endl;
}
protected:
Student s;
};
int main()
{
Recorder t;
return 0;
}
执行结果: