sizeof class with int , function, virtual function in C++?

A friend asked me "Wwhen you declare a class with member functions in C++, the member function's definition goes in the code memory. What memory does it take in the class object? 32-bit pointer?"

Well, run it for yourself and know. :-)

Here's a sample program:

#include <iostream>
using namespace std;

class A
{
  public:
    int a;
    A(int val)   { a=val; }

    A() { a = 0; }

    int show(void);
/*    virtual int func(void);*/
};

int A::show(void)
{
  cout << a << endl;
}

int main()
{
  A a(10);
  a.show();

  cout << sizeof(a) << endl << sizeof(A) << endl;

  return(0);
}

The bookmark has some more details from a good post on stackoverflow.

blog comments powered by Disqus