// 派生类的构造函数与基类的构造函数.cpp : Defines the entry point for the console application.
//如果基类有构造函数,则在生成派生类的对象时会先调用基类的构造函数,
//然后再调用派生类的构造函数。
#include "stdafx.h"
#include<iostream>
protected:
int num;
char name[10];
char sex;
public:
student(int n,char *na,char s)
{
num=n;
strcpy(name,na);
sex=s;
cout<<"基类的构造函数被调用"<<endl;
}//基类中带参数的构造函数。
//如果基类有构造函数,则在生成派生类的对象时会先调用基类的构造函数,
//然后再调用派生类的构造函数。
#include "stdafx.h"
#include<iostream>
using namespace std;
class student
{protected:
int num;
char name[10];
char sex;
public:
student(int n,char *na,char s)
{
num=n;
strcpy(name,na);
sex=s;
cout<<"基类的构造函数被调用"<<endl;
}//基类中带参数的构造函数。