class does not have any data member but it has some method . in this case the size of object of class is 1 byte.this pointer which is passed with object when member function is invoked . how is it possible object of 1 byte have this pointer - This pointer typically has size of void* and assume it is 4 bytes
-
`char` is also 1 byte and can have pointer to it (`char*`). – MikeCAT Sep 22 '15 at 05:44
-
The `this` pointer is not "passed with object" as you say. – Ulrich Eckhardt Sep 22 '15 at 05:46
-
This pointer doesn't belong to the Class object. Please refer http://stackoverflow.com/questions/16585562/where-is-the-this-pointer-stored-in-computer-memory for more info. – neo Sep 22 '15 at 05:46
-
The `this` pointer is **not** a class member, it is the location in memory where the class object is stored. An external object holds the pointer to the object which is (notionally) assigned to the `this` pointer when the method is invoked. – Galik Sep 22 '15 at 05:47
3 Answers
this doesn't belong to the Class object. this behaves mostly like a function argument. In your question "this pointer which is passed with object when member function is invoked", I would like to point out that this is not passed with object, Object address is passed to the this pointer.
Please refer Where is the 'this' pointer stored in computer memory? for more info on this.
The size of a pointer in C/C++ is always equal to the size of memory address length. (4 bytes)
The size of an class of empty fields is using a separate address. (1 byte)
if we have a class instance of this type, when you count it's size by
sizeof(instance) == 1
but
sizeof(&instance) == 4 (on 32 bits system)
so you can put an address of instance to a pointer like:
void *p = &instance;
here sizeof(p) == 4;
This needs 4 bytes to hold the address/pointer to instance.

- 1
- 2
The this
pointer is not a class member, the compiler adds it to the method calls behind the scenes as a hidden parameter.
Consider:
struct Object
{
void method(int i);
};
The compiler turns that into something like:
void Object::method(Object* this, int i); // note the extra first parameter
When you do:
Object object;
object->method(5);
The compiler does something like:
Object object;
Object::method(&object, 5);
The hidden first parameter is called this
.

- 47,303
- 4
- 80
- 117