×

Loading...

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 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: 问一个C++的问题

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论