forked from peter-can-write/cpp-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcasting.html
More file actions
16 lines (16 loc) · 1.89 KB
/
casting.html
File metadata and controls
16 lines (16 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 6.3 (452849)"/><meta name="altitude" content="518"/><meta name="author" content="petergoldsborough@hotmail.com"/><meta name="created" content="2015-02-28 17:34:41 +0000"/><meta name="latitude" content="46.62858276367184"/><meta name="longitude" content="13.82443237304688"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2015-02-28 17:34:49 +0000"/><title>Casting</title></head><body>
<div>
<div><span style="font-family: 'Helvetica Neue';">Prefer C++style casting over old-style, C casts and generally, try to avoid casting, especially dynamic_cast<> as it has very poor performance.</span></div>
<div><span style="font-family: 'Helvetica Neue';"><br/></span></div>
<div><span style="font-family: 'Helvetica Neue';">static_cast<type>(object) // Casts an object between similar types, e.g. int to double</span></div>
<div><span style="font-family: 'Helvetica Neue';"><br/></span></div>
<div><span style="font-family: 'Helvetica Neue';">reinterpret_cast<type>(object) // Casts an object from a completely different type to another type, e.g. class Foo() { } to char* </span></div>
<div><span style="font-family: 'Helvetica Neue';"><br/></span></div>
<div><span style="font-family: 'Helvetica Neue';">dynamic_cast<type>(object) // Casts between inheritance hierarchies, e.g. from Base pointer to Derived to Derived pointer</span></div>
<div><span style="font-family: 'Helvetica Neue';"><br/></span></div>
<div><span style="font-family: 'Helvetica Neue';">const_cast<type>(object) // Casts a way the const of an object</span></div>
</div>
<div><br/></div>
</body></html>