这个题不太理解
实现Student类,要求该类对象在创建时,可以自动生成学号Student s1 ; //学号1
Student stu[10]; //学号将依次是2……11
#include <iostream> class Student { public: Student() : id_(++gid_) { } private: size_t id_; static size_t gid_; friend std::ostream& operator<<( std::ostream& os, const Student& s ); }; size_t Student::gid_ = 0; std::ostream& operator<<( std::ostream& os, const Student& s ) { return os << s.id_; } using namespace std; int main( void ) { Student s1; Student stu[10]; cout << s1 << '\n'; for( size_t i=0; i!=sizeof(stu)/sizeof(stu[0]); ++i ) cout << stu[i] << '\n'; return 0; }
[此贴子已经被作者于2016-11-2 09:41编辑过]