0

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?

5
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Radical Edward
0

#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.

0

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

@tennis

> 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.

@venkat arun

> 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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.