Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual function is not listed in the vptr

The vptr index should display all the virtual functions, but in my case only 2 out of the 3 virtual functions are being displayed.

I am providing the complete code and the screenshots below :-

ClassHeader.h

#include <iostream>
using namespace std;

// Employee Class

class Employee
{
  public :
int salary ;
Employee(){cout << "Inside CTOR" << endl;}

virtual ~Employee() {cout << "Inside DTOR" << endl;}

virtual void pay(){cout << "Employee" << endl;}
};

// Manager Class

class Manager : public Employee
{
   public :

virtual void pay(){cout<< "Manager pay" << endl;}
virtual void Rank(){cout << "Manager Rank" << endl;}
};

// JuniorManager Class
class JuniorManager : public Manager
{
   public :

virtual void pay(){cout<< "JuniorManager pay" << endl;}
virtual void Rank(){cout << "JuniorManager Rank" << endl;}
};

Main.cpp

#include "ClassHeader.h"

void main()
{
    Manager *p = new Manager();

p->pay();
p->Rank();

p = new JuniorManager();
p->Rank();

Employee *pE = dynamic_cast<Employee*>(p);
pE->pay();

}

The Manager class has two virtual functions, pay and Rank, but only pay shows up in the vptr.

Can somebody please tell me, why Rank does not show up , even though its virtual function.

I am using Visual Studio 2008 , and with the latest updates, on Windows 7 64 bit.

enter image description here

JuniorManager Debugger Screenshot

It does not show the virtual functions either. Please see the image below.

enter image description here

like image 909
Sujay Ghosh Avatar asked Feb 06 '12 20:02

Sujay Ghosh


1 Answers

If you inspect the class as an Employee, since that class does not have Rank(), it will not show the Rank() in the vtable. Your screenshot shows the contents of Employee class.

"Yup, the debugger doesn't have sufficient type information to tell how long the array is. So it only displays the first element unless overridden."

http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/23d4e48e-520e-45b4-8c2f-65c11946d75d

like image 169
perreal Avatar answered Sep 21 '22 22:09

perreal