青山相待

            白云相爱

            梦不到紫罗袍共黄金带

            一茅斋

            野花开

            管甚谁家兴废谁成败

            陋巷单瓢亦乐哉

            贫,气不改!

            达,志不改!

谷歌C++编程为何禁止缺省参数

    C++的缺省参数尽量不要使用,结果可能出乎我们的意料,下面的程序大家看看输出结果是多少?

 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的朋友拿起编译器调试一下吧,呵呵 

posted @ 2014-07-14 18:35  Leo.Z  阅读(279)  评论(0编辑  收藏  举报