用指向基类对象的指针输出数据
2008-01-03 09:28
246 查看
#include "stdafx.h"
#include
#include
using namespace std;
class student{
private:
int num;
int age;
float score;
public:
student(int ,int ,float);
void display();
};
//定义构造函数
student::student(int n,int a,float sc):num(n),age(a),score(sc){}
void student::display(){//定义成员函数
cout pt=&gr;
pt->display();
return 0;
}
输出结果:
12222
22
97.4
353543
26
88.2
Press any key to continue
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1476001
#include
#include
using namespace std;
class student{
private:
int num;
int age;
float score;
public:
student(int ,int ,float);
void display();
};
//定义构造函数
student::student(int n,int a,float sc):num(n),age(a),score(sc){}
void student::display(){//定义成员函数
cout
pt->display();
return 0;
}
输出结果:
12222
22
97.4
353543
26
88.2
Press any key to continue
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1476001
相关文章推荐
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 用指向基类对象的指针输出数据
- 【4.17】建立一个对象数组,内放6个学生的数据(学号、成绩),用指针指向数组首元素,输出第2,4,6个学生的数剧。
- 建立一个对象数组,内放5个学生数据(学号、成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并从输出学号。
- Chapter9——建立一个对象数组,内放5个学生的数据(学号,成绩),设立一个函数max,用指向对象的指针做函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。
- 4,17建立对象数组,存放6个学生数据,指针指向数组首个元素,输出2,4,6个学生数据
- 建立一个对象数组,内放5个学生的数据(学号,成绩),用指向对象的指针做函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。
- 建立一个对象数组,内放5个学生数据(学号、成绩),用指针指向数组首元素,输出学生的数据
- C++ 基类指针指向派生类对象
- 为什么要用基类指针指向派生类对象?