It's highly against OOP principles to do such a thing. If you rely that the parent is always of class X then when setting a parent, accept a pointer to X and store it in a variable to X. Then no cast will be required and nobody will use your class in a way that could break it (i.e. by passing a parent of different class).