Another way, only need one member function to copy itself.

webcrawl (pushback)
#include "stdafx.h"
#include <iostream.h>

class Base
{
public:
int getTT()
{
return tt;
}
virtual void did(){};
void done();

Base *pBase;

protected:
void membercopy(Base *p)
{
tt = p->tt;
// and so on...
}
private:
int tt;
};

class Derived : public Base
{
public:
Derived(Base *p)
{
membercopy(p);
}
void did()
{
cout << "this is derived class" << endl;
cout << "tt = " << getTT() << endl;
}
private:
};

void Base::done()
{
tt = 8;
Base* b = new Derived(this);
b->did();
delete b;
}


int main(int argc, char* argv[])
{
Base b;
b.done();
return 0;
}
(#346433@0)
2002-1-25 -05:00

回到话题: 问一个C++的问题

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=346433