English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a class
class A
{
public:
list< int > myList;
}

sizeof( A) does not change even when i add items into myList. Is there another way to get the memory used by an object?

2006-12-22 08:57:04 · 1 answers · asked by Delta Force 2 in Computers & Internet Programming & Design

1 answers

sizeof() is a compile-time keyword that is not going to have any effect at runtime. It is replaced by the size of the class when the program is being compiled, so it is never going to change. You need to do something like this.
...
{
A my_obj;
int total_size = sizeof(my_obj) + sizeof(int)*my_obj.myList.size();
}

2006-12-22 10:05:02 · answer #1 · answered by Chris J 6 · 2 0

fedest.com, questions and answers