I created a simple object containing integer and several methods, only an integer primitive variable and compare their sizes. "sizeof ()" for the return value of "4". Why is this - should not one object, which is a composite type and contains information about methods that take up 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; }
( - ++) "" . , . - , , . - Foo ,
Foo
return_type some_member_function(Foo* ptr, /* other params */){...}
, . ptr -,
ptr
foo.some_member_function(/* other params */)
some_member_function(&foo, /* other params */)
, ptr ++, this. this - prvalue, , -.
this
PS: @greyfade, (-) virtual, " ". , . , , , .
virtual