The following is VC win32 console application, which can output what you want.

webcrawl (pushback)
#include "stdafx.h"
#include <iostream.h>
class Base
{
public:
int getTT()
{
return tt;
}
virtual void did(){};
void done();
private:
int tt;
};

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

void Base::done()
{
tt = 8; // only base variable was assigned 8
Base* b=new Derived;
b->tt = 8; // only through this way, the new instance's tt can be initialized.
b->did();
delete b;
}


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

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

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

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