why size of an empty class is 1 byte?what will be the size if we add a virtual function to that class?
An empty class must be at least one byte in size because the standard requires that every object must have a unique address. E.g., if Foo was an empty class, and foo1 and foo2 are objects of type Foo, then &foo1 == &foo2. This would break code that relies on addresses to do things (e.g. using addresses to resolve locking orders).