virtual table pointer confused

Discussion in 'C++' started by dost, May 10, 2011.

  1. dost

    dost Guest

    please see the following code.
    class A
    {
    public:
    virtual void F1(){printf("\nclass A :: F1() ");}
    };
    class B : public A
    {
    public:
    virtual void F2(){printf("\nclass B :: F1() ");}
    };

    int _tmain(int argc, _TCHAR* argv[])
    {
    A *pA = new A(); //
    B *pB = new B(); // Question A
    }

    Hi
    In the above code i was looking for virtual table pointer values on
    both statement.
    1 A *pA = new A(); here i see when object is created a new vptr is
    created and it has the address in static array for function A ::
    F1().
    2. B *pB = new B(); here i see the vptr address is different which is
    obvious and the address and entry of A :: F1(). But i cant see the
    entry of function B :: F2().
    thank you
    dost, May 10, 2011
    #1
    1. Advertising

  2. dost

    dost Guest

    On May 10, 11:44 am, dost <> wrote:
    > please see the following code.
    > class A
    > {
    >         public:
    >         virtual void F1(){printf("\nclass A :: F1()   ");}};
    >
    > class B : public A
    > {
    >         public:
    >         virtual void F2(){printf("\nclass B :: F1()   ");}
    >
    > };
    >
    > int _tmain(int argc, _TCHAR* argv[])
    > {
    >    A *pA = new A(); //
    >    B *pB = new B(); // Question A
    >
    > }
    >
    > Hi
    > In the above code i was looking for virtual table pointer values on
    > both statement.
    > 1    A *pA = new A();  here i see when object is created a new vptr is
    > created and it has the address in static array for function  A ::
    > F1().
    > 2.  B *pB = new B(); here i see the vptr address is different which is
    > obvious  and the address and entry of A :: F1(). But i cant see the
    > entry of function  B :: F2().
    > thank you


    where is the entry of B :: F2().
    dost, May 10, 2011
    #2
    1. Advertising

  3. On 10 Mai, dost wrote:

    > > please see the following code.
    > > class A
    > > {
    > > public:
    > > virtual void F1(){printf("\nclass A :: F1() ");}};

    >
    > > class B : public A
    > > {
    > > public:
    > > virtual void F2(){printf("\nclass B :: F1() ");}

    >
    > > };

    >
    > > int _tmain(int argc, _TCHAR* argv[])
    > > {
    > > A *pA = new A(); //
    > > B *pB = new B(); // Question A

    >
    > > }

    >
    > > Hi
    > > In the above code i was looking for virtual table pointer values on
    > > both statement.
    > > 1 A *pA = new A(); here i see when object is created a new vptr is
    > > created and it has the address in static array for function A ::
    > > F1().
    > > 2. B *pB = new B(); here i see the vptr address is different which is
    > > obvious and the address and entry of A :: F1(). But i cant see the
    > > entry of function B :: F2().
    > > thank you

    >
    > where is the entry of B :: F2().


    You should be a bit more specific about your problem. I guess that you
    mean that you cannot see the vtable-entries for B::F2 in the debugger
    window of MS Visual Studio 20XX. This is by design.

    Regards,
    Stuart
    Stuart Redmann, May 10, 2011
    #3
  4. dost

    dost Guest

    On May 10, 11:56 am, Stuart Redmann <> wrote:
    > On 10 Mai, dost wrote:
    >
    >
    >
    >
    >
    > > > please see the following code.
    > > > class A
    > > > {
    > > >         public:
    > > >         virtual void F1(){printf("\nclass A :: F1()   ");}};

    >
    > > > class B : public A
    > > > {
    > > >         public:
    > > >         virtual void F2(){printf("\nclass B :: F1()   ");}

    >
    > > > };

    >
    > > > int _tmain(int argc, _TCHAR* argv[])
    > > > {
    > > >    A *pA = new A(); //
    > > >    B *pB = new B(); // Question A

    >
    > > > }

    >
    > > > Hi
    > > > In the above code i was looking for virtual table pointer values on
    > > > both statement.
    > > > 1    A *pA = new A();  here i see when object is created a new vptr is
    > > > created and it has the address in static array for function  A ::
    > > > F1().
    > > > 2.  B *pB = new B(); here i see the vptr address is different which is
    > > > obvious  and the address and entry of A :: F1(). But i cant see the
    > > > entry of function  B :: F2().
    > > > thank you

    >
    > > where is the entry of B :: F2().

    >
    > You should be a bit more specific about your problem. I guess that you
    > mean that you cannot see the vtable-entries for B::F2 in the debugger
    > window of MS Visual Studio 20XX. This is by design.
    >
    > Regards,
    > Stuart

    @stuart i am sorry for that. well you are right its about looking in
    debugger window.
    So can to tell me another way of checking the entries in vptr.
    thakyou
    dost, May 10, 2011
    #4
  5. On 10 Mai, 09:07, dost <> wrote:
    > On May 10, 11:56 am, Stuart Redmann <> wrote:
    >
    >
    >
    > > On 10 Mai, dost wrote:

    >
    > > > > please see the following code.
    > > > > class A
    > > > > {
    > > > >         public:
    > > > >         virtual void F1(){printf("\nclass A :: F1()   ");}};

    >
    > > > > class B : public A
    > > > > {
    > > > >         public:
    > > > >         virtual void F2(){printf("\nclass B :: F1()   ");}

    >
    > > > > };

    >
    > > > > int _tmain(int argc, _TCHAR* argv[])
    > > > > {
    > > > >    A *pA = new A(); //
    > > > >    B *pB = new B(); // Question A

    >
    > > > > }

    >
    > > > > Hi
    > > > > In the above code i was looking for virtual table pointer values on
    > > > > both statement.
    > > > > 1    A *pA = new A();  here i see when object is created a new vptr is
    > > > > created and it has the address in static array for function  A ::
    > > > > F1().
    > > > > 2.  B *pB = new B(); here i see the vptr address is different which is
    > > > > obvious  and the address and entry of A :: F1(). But i cant see the
    > > > > entry of function  B :: F2().
    > > > > thank you

    >
    > > > where is the entry of B :: F2().

    >
    > > You should be a bit more specific about your problem. I guess that you
    > > mean that you cannot see the vtable-entries for B::F2 in the debugger
    > > window of MS Visual Studio 20XX. This is by design.

    >
    > > Regards,
    > > Stuart

    >
    > @stuart i am sorry for that. well you are right its about looking in
    > debugger window.
    > So can to tell me another way of checking the entries in vptr.
    > thakyou>


    I'm sorry, AFAIK there is no way to view all vtable entries.

    Regards,
    Stuart
    Stuart Redmann, May 10, 2011
    #5
  6. dost

    Krice Guest

    On 10 touko, 10:07, dost <> wrote:
    > @stuart i am sorry for that. well you are right its about looking in
    > debugger window.
    > So can to tell me another way of checking the entries in vptr.


    So, why do you need to know anything about how the underlying
    vtable is working? Just let it do the magic.
    Krice, May 11, 2011
    #6
  7. dost

    red floyd Guest

    On May 11, 12:31 pm, Krice <> wrote:
    > On 10 touko, 10:07, dost <> wrote:
    >
    > > @stuart i am sorry for that. well you are right its about looking in
    > > debugger window.
    > > So can to tell me another way of checking the entries in vptr.

    >
    > So, why do you need to know anything about how the underlying
    > vtable is working? Just let it do the magic.


    Probably homework.
    red floyd, May 12, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Winter
    Replies:
    9
    Views:
    607
    Michael Winter
    Sep 24, 2003
  2. DaKoadMunky
    Replies:
    4
    Views:
    4,268
  3. =?iso-8859-1?B?RnJhbmstUmVu6SBTY2jkZmVy?=

    tweaking the virtual function table pointer

    =?iso-8859-1?B?RnJhbmstUmVu6SBTY2jkZmVy?=, Sep 23, 2005, in forum: C++
    Replies:
    7
    Views:
    378
    Alf P. Steinbach
    Sep 23, 2005
  4. archimed7592
    Replies:
    4
    Views:
    728
    =?UTF-8?B?UGF3ZcWC?=
    May 30, 2007
  5. somenath
    Replies:
    2
    Views:
    147
    somenath
    Aug 29, 2013
Loading...

Share This Page