What if object is not a Class? try_as<> will return NULL in that case, what does real_class do then? Does it crash / work correctly? Make sure to cover that case then also for the tests so we know that. Right now it's hard to say / give feedback on it because there are no tests, so not really sure what you did and what you didn't consider as cases :).