-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
using namespace std; | ||
class numbered { | ||
public: | ||
numbered(numbered &){ | ||
mysn = seq++; | ||
} | ||
numbered() { | ||
mysn = seq++; | ||
} | ||
int mysn; | ||
private: | ||
static int seq; //声明静态成员 | ||
}; | ||
int numbered::seq = 0; //定义并初始化静态成员(静态成员一般必须在类内声明,类外定义和初始化) | ||
void f(numbered s) | ||
{ | ||
cout << s.mysn << endl; | ||
} | ||
|
||
void f1(const numbered &s) | ||
{ | ||
cout << s.mysn << endl; | ||
} | ||
|
||
int main() | ||
{ | ||
numbered a, b = a, c = b; | ||
f(a);f(b);f(c); | ||
f1(a);f1(b);f1(c); | ||
system("pause"); | ||
return 0; | ||
} | ||
//2016年6月11日16:18:58 | ||
//实验室 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters