posts - 311, comments - 0, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

(地基工)VC析构函数

Posted on 2011-03-02 10:31 点点滴滴 阅读(144) 评论(0)  编辑 收藏 引用 所属分类: 02 编程语言
析构函数使用virtual关键字,子类会先调用自己的析构函数然后自动调用父类的析构函数,否则直接调用当前的承接类的析构函数。



class test1
{
public:
    
virtual void animation()
    {
        cout 
<< "test1 animation" << endl;
    }

    
virtual void animation1() = 0;

    
virtual ~test1()
    {
        cout 
<< "test1 destroy animation" << endl;
    }
};
class test2 : public test1
{
public:
    
virtual void animation1()
    {
        cout 
<< "test2 animation1" << endl;
    }
    
void animation()
    {
        cout 
<< "test2 animation" << endl;
    }

     
~test2()
    {
        cout 
<< "test2 destroy animation" << endl;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
//    allocatePractice();
    test1* test = new test2();
    test
->animation();
    test
->animation1();
    delete test;

//     //定义
//     std::pair<int, string> ming(1,"ming1");
//     std::map<int ,string> authors;
//     //插入
//     authors.insert(make_pair(3,"ming3"));
//     authors.insert(map<int, string>::value_type(2,"ming2"));
//     authors.insert(ming);    
// 
//     cout << authors[4] << endl;
    

    
return 0;
}