Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2508573
  • 博文数量: 308
  • 博客积分: 5547
  • 博客等级: 大校
  • 技术积分: 3782
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 09:47
个人简介

hello world.

文章分类

全部博文(308)

分类: C/C++

2010-11-18 16:26:03

#include <iostream>
using namespace std;

class Student
{
    public:
    Student(int n,float s):num(n),score(s){}
    
    void change(int n,float s) const
    {
        num = n;
        score = s;
    }
    
    void display() const
    {
        cout << num << " " << score << endl;
    }
    
    void fun(Student &p,int n,float s)
    {
         p.change(n,s);
         p.display();
    }
    
    private:
    mutable int num;
    mutable float score;
};

int main()
{
    Student stud(101,78.5);
    Student stud1(101,11.8);
    const Student * p = &stud; //定义指向常对象的指针变量

    p = &stud1; //可以进行更新指针的指向

    p->display();
    p->change(101,80.5);
    p->display();
    
    system("pause");
    return 0;
}


运行结果:
101 11.8
101 80.5

阅读(1251) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~