1 #include <iostream>
 2 using namespace std;
 3 class A{
 4 public:
 5     A &set(char);
 6     const A &display();
 7 //private:
 8     char a1 = 'l';
 9 };
10 inline A &A::set(char c)
11 {
12     a1 = c;
13     return *this;
14 }
15 
16 inline const A &A::display()
17 {
18     cout << a1 << endl;
19     return *this;
20 }
21 
22 int main()
23 {
24 A screen;
25 screen.display().set('a');   //错误,不能修改const对象;
26 screen.a1 = 'z';
27 //.set('l');
28 return 0;
29 }

 

相关文章:

  • 2021-10-03
  • 2021-09-04
  • 2021-07-01
  • 2021-08-01
猜你喜欢
  • 2021-12-29
  • 2022-12-23
  • 2021-06-12
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案