Note that there are some explanatory texts on larger screens.

plurals
  1. POUsage of const directive in C++ in general, in particular in Tiny XML Library:
    primarykey
    data
    text
    <p>I'm an experienced developer in a few compiled OOP languages, particularly Object Pascal and C#. Have 'messed around' with C++ for years but recently started getting more serious about C++ development.</p> <p>Most of concepts in C++ are quite easy for me to grasp based on my experience with other languages. But one thing that I'm finding quite difficult is the ways in which the <code>const</code> directive is used and how it behaves in C++.</p> <p>In particular, at the moment I'm faced with this problem, using the <a href="http://www.grinninglizard.com/tinyxml/" rel="nofollow">TinyXML Library</a> in Netbeans C++ IDE, on an Ubuntu 12.04 machine and default mingW/G++ tool chain:</p> <p>I'm calling this function: </p> <pre><code>TiXmlNode::TiXmlNode* FirstChild() </code></pre> <p>In the TinyXML source there are two overloaded public versions of this function in class <code>TiXmlNode</code>:</p> <pre><code>const TiXmlNode* FirstChild() const { return firstChild; } TiXmlNode* FirstChild() { return firstChild; } </code></pre> <p>They are identical except for the const directive. I assumed that the version called would be dependent on how I declared the variable I was loading from the function, for example:</p> <pre><code>const TiXmlNode* aNode = node-&gt;FirstChild(); </code></pre> <p>Would call the const version of the function</p> <pre><code>TiXmlNode* aNode = node-&gt;FirstChild(); </code></pre> <p>Would call the second version, without const.</p> <p>But when I try to use the second form in my code, I get a compiler error: </p> <blockquote> <p><strong>error: invalid conversion from ‘const TiXmlNode*’ to ‘TiXmlNode*’ [-fpermissive]</strong></p> </blockquote> <p>Why is this happening? How do I use the version of the function without const? What am I missing here? </p> <p>More - where can I find a good summary of the usages of <code>const</code> directive in C++ 11.</p>
    singulars
    1. This table or related slice is empty.
    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. 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