I have created simple object containing integer and few methods, integer primitive variable alone and compare their sizes. "sizeof()" for both returned value of "4". Why is that - shouldn't object that is composite type and contains information about methods take more space?
#include <iostream>
class Person{
private:
int a;
public:
void hello(){
std::cout << "hello";
}
void DoSomething(){
a++;
}
};
int main(){
int a;
Person p;
std::cout << sizeof(a) << std::endl;
std::cout << sizeof(p) << std::endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire