×

Loading...

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

#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;
}
Report

Replies, comments and Discussions: