f0905.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //=====================================
- // f0905.cpp
- // 对象成员的默认构造
- //=====================================
- #include<iostream>
- using namespace std;
- //-------------------------------------
- class StudentID{
- int value;
- public:
- StudentID(){
- static int nextStudentID = 0;
- value = ++nextStudentID;
- cout<<"Assigning student id "<<value<<"n";
- }
- };//-----------------------------------
- class Student{
- string name;
- StudentID id;
- public:
- Student(string n = "noName"){
- cout <<"Constructing student " + n + "n";
- name = n;
- }
- };//-----------------------------------
- int main(){
- Student s("Randy");
- }//====================================