c++类学习心得(一)

 1 #include<iostream>
2 #include"std_lib_facilities.h"
3 using namespace std;
4 class practice
5 {
6 public:
7 practice& a(char m)
8 {
9 cout<<m;
10 return *this;
11 }
12 practice& b(char n)
13 {
14 cout<<n;
15 return *this;
16 }
17 private:
18 char m;
19 char n;
20 };
21 int main()
22 {
23 practice pp;
24 char aa,bb;
25 cin>>aa>>bb;
26 pp.a(aa).b(bb);
27 keep_window_open();
28 }

第26行中“.”后必须要连接类成员,所以类的成员函数中返回的类型为*this。

posted @ 2012-02-06 16:30  windynightst  阅读(336)  评论(0编辑  收藏  举报