Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Depending on the concrete code <code>typeid</code> returns different things. Additionally <code>name()</code> can return anything (including making the first letter uppercase or removing *), it is only for debuging. Now I have a few different posible answers what <code>typeid(animal).name()</code> can return.</p> <p>Version 1 <code>animal</code> is a class name:</p> <pre><code>struct animal { virtual ~animal() {} }; struct dog : animal {}; struct cat : animal {}; struct bird : animal {}; int main() { std::cout &lt;&lt; typeid(animal).name() &lt;&lt; std::endl; // animal return 0; } </code></pre> <p>Version 2 <code>animal</code> is a typedef to <code>Animal</code>:</p> <pre><code>struct Animal { }; struct Dog : Animal {}; struct Cat : Animal {}; struct Bird : Animal {}; int main() { typedef Animal animal; std::cout &lt;&lt; typeid(animal).name() &lt;&lt; std::endl; // Animal return 0; } </code></pre> <p>Vesion 3 <code>animal</code> is a pointer:</p> <pre><code>struct Animal { }; struct Dog : Animal {}; struct Cat : Animal {}; struct Bird : Animal {}; int main() { Dog d; Animal* animal=&amp;d; std::cout &lt;&lt; typeid(animal).name() &lt;&lt; std::endl; // Animal* return 0; } </code></pre> <p>Version 4 <code>animal</code> is a object:</p> <pre><code>struct Animal { }; struct Dog : Animal {}; struct Cat : Animal {}; struct Bird : Animal {}; int main() { Animal animal; std::cout &lt;&lt; typeid(animal).name() &lt;&lt; std::endl; // Animal return 0; } </code></pre> <p>Version 6 <code>animal</code> is a reference to a <strong>non polymorphic</strong> objcet:</p> <pre><code>struct Animal { }; struct Dog : Animal {}; struct Cat : Animal {}; struct Bird : Animal {}; int main() { Dog d; Animal&amp; animal=d; std::cout &lt;&lt; typeid(animal).name() &lt;&lt; std::endl; // Animal return 0; } </code></pre> <p>and version 7 <code>animal</code> is a reference to a <strong>polymorphic</strong> object:</p> <pre><code>struct Animal { ~virtual Animal() {} }; struct Dog : Animal {}; struct Cat : Animal {}; struct Bird : Animal {}; int main() { Dog d; Animal&amp; animal=d; std::cout &lt;&lt; typeid(animal).name() &lt;&lt; std::endl; //Dog return 0; } </code></pre> <p>As others have written it's better not to rely on <code>name()</code>. But without some code it's not easy to say what's correct.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload