问一个C++的问题

oasis (oasis)
derived.cpp
#include "Base.h"
class Derived : public Base
{
public:
void did(){cout << "this is derived class" << endl;
cout << "tt = " << getTT() << endl;}
private:
};

base.cpp
#include <iostream.h>
class Base
{
public:
int getTT() { return tt;}
void did(){};
void done();
private:
int tt;
};

int main()
{
Base b;
b.done();
return 0;
}

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

问题:
我想在base class内部,定义一个base pointer, 用derived class初始化,同时又让他是这个base class的derived class, 也就是说,初始化完成后,b->did()应该能够能够打印出
this is derived class
tt=8

Base* b=new Derived; //???????????????????????]
这一句有问题,谁知道应该怎样初始化?
在base class外面好办,在里面怎么办?行得通吗?

谢谢
(#346324@0)
2002-1-24 -05:00

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

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

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