1. an int and a class with only an int member, are they of the same size?
2. what is the size of a class containing 4 ints and a virtual function?
and why can't you try this in a C++ compiler?
#2 depends on the compiler and operating system. The size of an int in a 32-it program may not be the same as in a 16 or 64-bit program.
1) Must be, depending on the compiler
2) I don't think functions occupy memory (they occupy it only once, and not everytime you create an object. Again this depends on the compiler.
> 1. an int and a class with only an int member, are they of the same size?
Maybe. The size of a class will be the total bytes of the data members and any padding. It is the padding that gets you on this question.
> 2. what is the size of a class containing 4 ints and a virtual function?
The size of 4 ints, plus padding, plus whatever storage is needed for the virtual mechanics used by the compiler.
> 2) I don't think functions occupy memory
Functions are not stored in each object, but virtual functions usually mean that each object gets a vtable, and that adds to the size of each object.