Skip to content

create const_cast.md // dynamic_cast.md#17

Open
SoWeBegin wants to merge 8 commits intoeisenwave:masterfrom
SoWeBegin:patch-1
Open

create const_cast.md // dynamic_cast.md#17
SoWeBegin wants to merge 8 commits intoeisenwave:masterfrom
SoWeBegin:patch-1

Conversation

@SoWeBegin
Copy link
Copy Markdown

No description provided.

@SoWeBegin SoWeBegin changed the title Create const_cast.md create const_cast.md // dynamic_cast.md Feb 9, 2022
Comment thread const_cast.md Outdated
to undefined behavior, but also because it's very easy to break the constness-related best practices while using it.

## Also See
To learn about all the rules related to const_cast, visit
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this sentence, it's redundant

Comment thread dynamic_cast.md Outdated


## Also See
To learn about all the rules related to dynamic_cast, visit
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this sentence, it's redundant

Comment thread dynamic_cast.md Outdated
```

## Notes
Downcasting can be applied through static_cast as well, but in that case no runtime check is performed.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to shorten the language in general, minimizing the word count. In this case "You can downcast with static_cast as well, but no runtime check is performed."

Comment thread dynamic_cast.md Outdated
if the conversion could not be applied. This also implies a little overhead when using this cast.

## Useful conversions
dynamic_cast is mostly used when we need to downcast a base class to its derived class.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use backticks for keywords

Comment thread const_cast.md
## Examples
- Remove constness:
```cpp
int main() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce LOC by removing int main(), we don't need a whole program to demonstrate how it works

Comment thread const_cast.md

## Also See
To learn about all the rules related to const_cast, visit
[cppreference: const_cast](https://en.cppreference.com/w/cpp/language/const_cast)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more links in both articles. Stackoverflow posts, CppCoreGuidelines recommendations for dynamic-cast and const-cast, etc.

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

Successfully merging this pull request may close these issues.

2 participants