about dynamic binding

peer is a base class, aopeer is a derived class
and schedule_new_chunk() is a virtual function defined in peer
and overridden in the derived class aopeer

peer *ppeer= new aopeer();

when execute the statement: ppeer->receive_chunk()

the function schedule_new_chunk()
will be the which version of the function?
in the base class or the derived class?

1
2
3
4
5
6
7
8
void Peer::receive_chunk(PChunk pchunk, PPeer from)
{
	p_tot_chunks_recd++;
	window()->insert(pchunk);
	stats()->record_arrival(pchunk);
	if (!p_upload_busy) {
		schedule_new_chunk();
	}
Last edited on
It will call the derived (overridden) function.
if there is no tricky part..
the pointer is of derived type so it should be derived.. vtable will have the address of derived class function.
the pointer is of derived type
---------------
?? I think the pointer is of base type
but it point a derived object
Topic archived. No new replies allowed.