1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Detail about How VPTR and Virtual table works

Discussion in 'C++' started by asadullah.ansari, Jan 22, 2008.

  1. rahul.mca2001

    rahul.mca2001 New Member

    Joined:
    Feb 13, 2008
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    0
    congrats sir
     
  2. nerdpower

    nerdpower New Member

    Joined:
    Mar 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bellevue, WA
    This article is wrong ! The method the author describes only works for particular C++ compilers. Also the method used here is machine specific. The author has made assumptions on the size of the integer pointer which changes on different platforms. Its cool to tinker and find out how your compiler implements virtual function but this is not the same for all compilers and platforms.

    There is **NOTHING** in the C++ Standard i.e. ISO/IEC 14882 (2003) that mentions how they are to be implemented. There are different ways to implementing virtual tables/pointers internally. If you want to understand how virtual functions (polymorphism) work pickup the ISO standard and start reading.
     
  3. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    I have already read the ISO standard, after reading i thought about it. I make it and test
    on solaris system. This article gives you a idea about VPTR.

    Can you tell me any compiler which is behaving different that whatever i descrived?
    Offcourse compiler can implement any concept in different ways. Just go and read Iso standard for VPTR how it's designed?
     
  4. alramesh

    alramesh New Member

    Joined:
    Feb 5, 2008
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0

    what's wrong. I got everything . I think you did'nt read c++ standard.
     
  5. nerdpower

    nerdpower New Member

    Joined:
    Mar 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bellevue, WA
    VPTR is nothing to do with the C++ Specification.
     
  6. nerdpower

    nerdpower New Member

    Joined:
    Mar 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bellevue, WA
    http://www.thefreecountry.com/compilers/cpp.shtml

    Are you sure that your explanation works for all these compilers?

    IIRC, this wont work with MSVC. I have no problem with your explanation, you should mention that it will only work for x,y,z compiler under a,b,c platform. If you don't mention that, people reading your article will assume that this is a global standard for all C++ compilers.
    What ISO standard? Can you quote the actual standard that describes the size of vptr as 4 bytes? You can also define vtbl in different ways.
     
  7. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA


    i have mention above it's for 32 bit machine
     
  8. talk2mohdsaif

    talk2mohdsaif New Member

    Joined:
    Mar 8, 2009
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Hamirpur(hp)
    Very Nice artical bro..........................
     
  9. talk2mohdsaif

    talk2mohdsaif New Member

    Joined:
    Mar 8, 2009
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Hamirpur(hp)
    really nice article..
    i was confusion in vtable but now i know all about vtable and vptr.......
     

Share This Page