几个有意思的代码

TBool CExample::FindL(TDes& aData)
{
RFile file;
buffer = HBufC::NewL(KMaxBufferLength);
TPtr ptr = buffer.Des();
...
file.Read(ptr);
aData.Copy(ptr);
}

 

 

#include <iostream>
#include <string>

using namespace std;

class A
{
public:
    A() { cout << "A" << endl; }
    virtual ~A() { cout << "~A" << endl; }
    virtual void show() { cout << "A show" << endl; }
};

class B : public A
{
public:
    B() { cout << "B" << endl; }
    ~B() { cout << "~B" << endl; }
    void show() { cout << "B show" << endl; }

    static void* operator new(size_t size)
    {
        return ::malloc(size);
    }

    static void operator delete(void* p)
    {
        cout << "operator delete" << endl;
        static_cast<B*>(p)->show();
        ::free(p);
    }
};

int main()
{
    B* b = new B;
    b->show();
    delete b;
    return 0;
}
posted @ 2010-04-19 10:23  秋天的风  阅读(278)  评论(0编辑  收藏  举报