C++笔记(3)类中与类外的运算符重载.
重载>> 1#include <iostream>
2using namespace std;
3
4//类内重载
5class string_A
6{
7 public:
8 void operator >> (istream & input)
9 {
10
11 };
12};
13
14void main()
15{
16 string_A string_a;
17 //cin>>string_a; //Fail!!
18 string_a>>cin;
19}
20
21//类外重载
22class string_B
23{
24 public:
25
26};
27
28void operator >> (istream & input, string_B &output)
29{
30
31};
32
33void Test()
34{
35 string_B string_b;
36 cin>>string_b;
37 //string_b>>cin; //Fail
38}
2using namespace std;
3
4//类内重载
5class string_A
6{
7 public:
8 void operator >> (istream & input)
9 {
10
11 };
12};
13
14void main()
15{
16 string_A string_a;
17 //cin>>string_a; //Fail!!
18 string_a>>cin;
19}
20
21//类外重载
22class string_B
23{
24 public:
25
26};
27
28void operator >> (istream & input, string_B &output)
29{
30
31};
32
33void Test()
34{
35 string_B string_b;
36 cin>>string_b;
37 //string_b>>cin; //Fail
38}