f0812.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //=====================================
- // f0812.cpp
- // misuse data member
- //=====================================
- #include<iostream>
- using namespace std;
- //-------------------------------------
- class Student{
- int n;
- string name;
- public:
- void set(string str){
- static int number = 0;
- name = str;
- n = ++number;
- }
- void print(){ cout<<name<<" -> students are "<<n<<" numbersn"; }
- };//-----------------------------------
- void fn(){
- Student s1;
- s1.set("Jenny");
- Student s2;
- s2.set("Randy");
- s1.print();
- }//------------------------------------
- int main(){
- Student s;
- s.set("Smith");
- fn();
- s.print();
- }//====================================