天天看點

【C++學習】成員函數重載

1. 
#include <iostream>
2. #include <string>
3. using namespace std;
4. class Cube
5. {
6. 
7. public:
8. 
9.  Cube()
10.     {
11.         cout<<"構造函數";
12.     }
13.     void func (int x)
14.     {
15.       cout<<x<<endl;
16.     }
17.     void func(int x,int y)
18.     {
19.      cout<<"x:"<<x<<"y:"<<y<<endl;
20.     }
21. 
22. private:
23.     int x,y;
24. };
25. 
26. 
27. void main()
28. {
29.     Cube c;
30.     c.func(1,43);
31. 
32. 
33. }
34.      

繼續閱讀