As others said, it is undefined behavior. Regarding the reason why it appears to work is that you are not trying to access the member variable a inside the print(). All the instances of the class share same memory for the code of print() hence this pointer is not required to access the method. However, if you try to access a inside the method you are most likely to get an access violation exception.