1 #include "mainwindow.h"
2 #include <QApplication>
3 #include <QPushButton>>
4
5 //重载的三种形式,成员函数重载
6 //友元函数重载,可以使用私有变量以及保护变量
7 //一般函数重载都是公有变量
8
9 class buttons
10 {
11 QPushButton *p;
12 int n;
13
14 public:
15 buttons():n(10)
16 {
17 p = new QPushButton[10];
18 for(int i=0;i<10;i++)
19 {
20 p[i].resize(100,100);
21 p[i].move(i*100,i*100);
22 p[i].show();
23 }
24 }
25 ~buttons()
26 {
27 delete[] p;
28 }
29
30 //重载[]
31 QPushButton *operator [](int i)
32 {
33 if(i>=0 && i<=n-1)
34 {
35 return this->p+i;
36 }
37 }
38
39 //重载*
40 QPushButton *operator *()
41 {
42 return this->p;
43 }
44
45 //重载->
46 QPushButton *operator ->()
47 {
48 return this->p+5;
49 }
50
51 //重载->*
52 QPushButton *operator ->*(int i)
53 {
54 return this->p+i;
55 }
56 };
57
58
59 int main(int argc, char *argv[])
60 {
61 QApplication a(argc, argv);
62
63 buttons bs;
64 // bs[3]->hide();
65 // (*bs+2)->hide();
66 //bs->hide();
67 // bs->*hide();
68 (bs->*1)->hide();
69 return a.exec();
70 }