0

here is my program , I am little confuse about how many vtable and virtualpointer will be created for the program. and if we don't create a virtual function in derive class will vpinter will create for that.

#include<iostream>
using namespace std;

class abc
{
    virtual void  aaa();
};
void abc::aaa()
{
}
class ddd:public abc
{
    void ddda();
    virtual void sddd();
};
void ddd::ddda()
{
}
void ddd::sddd()
{
}
int main()
{
    abc d;
    ddd *y;
    abc *ab;
}
  • Exactly what actual problem are you trying to solve? Although I'm generally aware of the basic principals of typical virtual inheritance implementations, I can't say that in the 25 years of hacking C++ I really cared about vtable implementation particulars, nor how many different actual vtables or virtual pointers my program creates. That's my C++ compiler's job, to figure it out; and I'm happy to let my compiler do its job. Unless, of course, my job is to write a C++. But it's not. So, unless you're writing your own C++ compiler, I don't see why you would care, about something like this. – Sam Varshavchik Sep 09 '18 at 03:24
  • baesd on the creation of the vpointer i will have the clear idea on how at run time virtual function is invoked – subhasmita panda Sep 09 '18 at 03:29
  • A vtable is an implementation detail. Although it is a common implementation approach, it is not a required approach. In any event, unless you are debugging a C++ compiler, you would not need visibility of the creation of vtables. And, if you are debugging a C++ compiler, you would know how to work it out. – Peter Sep 09 '18 at 05:03

1 Answers1

0

I had read some information from "Effective C++","every class has a virtual table if it has virtual function,the virtual table will include the virtual pointer of virtual function".I think it will help you.