CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: size of class

  1. #1
    Join Date
    May 1999
    Posts
    3

    size of class

    class name {
    private:
    int first;
    int second;
    public:
    int func(int);
    };

    If I type the size of the class it says = 8 where the size of int is 4.

    If I made the function "func" as virtual the size of class becomes 12. Why?
    What the magic with virtual.


  2. #2
    Join Date
    May 1999
    Posts
    69

    Re: size of class

    there is a vtable (virtual function table) that holds the address of the virtual function. This is necessary to choose the right function depending on the actual object instance (ie inherited function calls other function which might be overloaded by instance class, if directly called, old (not overloaded) code would execute. Called through vtable -> right function code executes. 32 bit pointer eq 4 byte memory space

    hope this helps

    chrislaw

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured