谷歌C++編程爲什麼禁止缺省參數

    C++的缺省參數儘可能不要使用,結果可能出乎咱們的意料,下面的程序你們看看輸出結果是多少?ios

 1 #include <iostream>
 2  using  namespace std;
 3 
 4  class A
 5 {
 6          public:
 7          virtual  void pt( int ipt,  int num =  1)
 8         {
 9                 cout << ipt << endl;
10                 cout << num << endl;
11         }
12 };
13 
14  class B: public A
15 {
16          public:
17          virtual  void pt( int ipt,  int num =  2)
18         {
19                 cout << ipt << endl;
20                 cout << num << endl;
21         }
22 };
23 
24  int main()
25 {
26         A *p =  new B;
27         p->pt( 3);
28 }

     想要回答3,2的朋友拿起編譯器調試一下吧,呵呵 spa

相關文章
相關標籤/搜索