<!-- HTML header for doxygen 1.8.8--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- For Mobile Devices --> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta name="generator" content="Doxygen 1.8.15"/> <script type="text/javascript" src="jquery.min.js"></script> <title>rttr: Register Class Hierarchy</title> <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>--> <script type="text/javascript" src="dynsections.js"></script> <link rel = "shortcut icon" type = "image/x-icon" href = "favicon.ico"> <link rel = "stylesheet" href = "fonts/ptsans_regular_macroman/stylesheet.css"> <link rel = "stylesheet" href = "fonts/source_code_pro_regular/stylesheet.css"> <link href="doxygen.css" rel="stylesheet" type="text/css" /> <link href="custom-doxygen.css" rel="stylesheet" type="text/css"/> <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="custom-bootstrap.css"> <script src="bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript" src="doxy-boot.js"></script> </head> <body> <!-- <nav class="navbar navbar-default" role="navigation"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand">rttr 0.9.6</a> </div> </div> </nav> --> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div class="content" id="content"> <div class="container"> <div class="row"> <div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;"> <div style="margin-bottom: 15px;"> <!-- end header part --> <!-- Generated by Doxygen 1.8.15 --> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(function() { initMenu('',false,false,'search.php','Search'); }); /* @license-end */</script> <div id="main-nav"></div> </div><!-- top --> <div class="PageDoc"><div class="header"> <div class="headertitle"> <div class="title">Register Class Hierarchy </div> </div> </div><!--header--> <div class="contents"> <div class="textblock"><p>Within the current C++ standard it is not possible to extract a class hierarchy automatically from a certain type. Therefore the programmer has to put a certain macro inside every class in order to provide this information. Additionally this macro will be needed to retrieve the information about the most derived <a class="el" href="classrttr_1_1type.html">type</a> of a current instance.</p> <p>The macro you have to insert in the class declaration is named: <a class="el" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE()</a></p> <p>Suppose we have a base struct called <code>Base</code>: </p><div class="fragment"><div class="line"><span class="keyword">struct </span>Base</div><div class="line">{</div><div class="line"> <a class="code" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE</a>()</div><div class="line">};</div></div><!-- fragment --><p> Place the macro <a class="el" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE()</a> somewhere in the class, it doesn't matter if its under the public, protected or private class accessor section.</p> <p>Into the derived class you put the same macro, but now as argument the name of the parent class. Which is in this case <code>Base</code>. </p><div class="fragment"><div class="line"><span class="keyword">struct </span>Derived : Base</div><div class="line">{</div><div class="line"> <a class="code" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE</a>(Base)</div><div class="line">};</div></div><!-- fragment --><p>When you use multiple inheritance you simply separate every class with a comma. </p><div class="fragment"><div class="line"><span class="keyword">struct </span>MultipleDerived : Base, Other</div><div class="line">{</div><div class="line"> <a class="code" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE</a>(Base, Other)</div><div class="line">};</div></div><!-- fragment --><p> Remark that the order in which you declare here the multiple inheritance, has an impact later when retrieving properties of a class. So it is best practice to use the same order like in your class. RTTR supports to register even virtual base classes. </p><dl class="section remark"><dt>Remarks</dt><dd>The only limitation you have is: It is <b>not</b> possible to register a class twice in the same class hierarchy.</dd></dl> <p>When no class hierarchies are used at all, it is <b>not necessary</b> to use the macro. However it is best practice to place it inside every class. This macro will also enable the possible usage of an own cast operator called: <code>rttr_cast</code>. How this will be done, is discussed in the <a class="el" href="rttr_type_rttr_cast_page.html">next</a> chapter.</p> <h2>Summary </h2> <ul> <li>to retrieve meta information of derived and base classes or using <a class="el" href="namespacerttr.html#ab3dd8b62e5ddca4c1d57cc572ba6bb81">rttr_cast</a>, it is necessary to place the macro: <a class="el" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE()</a> inside every class declaration</li> <li>the macro is <b>not</b> needed when working with classes which will be not inherited, e.g. POD classes</li> </ul> <hr/> <div class="btn btn-default doxy-button"><a class="el" href="rttr_type_info_page.html">previous</a></div><div class="btn btn-default doxy-button"><a class="el" href="rttr_type_rttr_cast_page.html">next</a></div> </div></div><!-- PageDoc --> </div><!-- contents --> <!-- HTML footer for doxygen 1.8.9.1--> <!-- start footer part --> <hr class="footer"/> <address class="footer"> <small> Generated on Thu Apr 11 2019 20:05:57 for rttr - 0.9.6 by <a href="http://www.doxygen.org/index.html">doxygen</a>. </small> </address> </body> </html>