非是非
Thinking, Express
|

测验题目

问题:
    class CDemo {
      public:
        CDemo(const char *str);
        ~CDemo();
      private:
        char name[20];
    };
    
    CDemo::CDemo(const char* str) {
        strcpy(name,str);
        cout < <"cout:Construction called for " < <name < <endl;
    }
    
    CDemo::~CDemo() {
       cout < <"cout:Destruction called for " < <name < <endl;
       printf(" printf:Destruction called for %s\n",name);
    }
    
    
    static CDemo GlobleObject("globeobject"); 
    
    void main() {
      CDemo LocalObjectInMain("localobjectinmain");
      CDemo * pHeapObjectInMain=new CDemo("heapobjectinmain");
      CDemo *pHeapObjectInFunc=new CDemo("heapobjectinfunc");
      static CDemo StaticObject="staticobject";
    } 
    
    这里globeobject的析构并没有被显示出来,为什么呢? 
    
    参考答案:
    因为cout析构在GlobleObject析构前.
    非是非 | 联系 | 关于 | 向开发者捐赠 |

    版权所有 © 非是非, 2007~2015

    我觉得这个站点或页面: 有用 没用 有趣 无趣 有错 |