Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add downcast helper script / function / class #22

Open
kpvdr opened this issue May 5, 2017 · 0 comments
Open

Add downcast helper script / function / class #22

kpvdr opened this issue May 5, 2017 · 0 comments

Comments

@kpvdr
Copy link
Owner

kpvdr commented May 5, 2017

There are many places in the code where a child class is known to exist, but we have only the parent pointer. Currently this is handled as follows:

Parent* parentPtr = ...;
Child* ChildPtr = dynamic_cast<Child*>(parentPtr);
if (ChildPtr == nullptr)  {
    throw Error(...);
}
\* use childPtr *\

This pattern is used many times, it might help simplify the code and make it easier to read if there were a simple helper to do all this. One possibility:

Parent* parentPtr = ...;
Child* childPtr = cast_and_check<Child*>(parentPtr);
\* use childPtr *\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant