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.
JuniorManager Debugger Screenshot
It does not show the virtual functions either. Please see the image below.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With