Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, I hardly believe your code will compile while in your <code>main</code> you try to get access to private data member <code>name</code>.</p> <p>About <code>&amp;</code>. It is really hard to define where to start. In short <code>std::string &amp;name</code> is called <code>reference</code> to object of type <code>std::string</code>. Reference is somehow an <em>alias</em> to some other object. The main feature is, that you always have to initialize refence to object while creating and you can't reinitialize reference to point to another object. More about this feature you can read in <a href="https://isocpp.org/wiki/faq/references" rel="nofollow">C++ FAQ</a></p> <p><strong>EDIT</strong> Generally you can declare public, protected and private members of your class in with arbitrary ordering:</p> <pre><code>class MyClass { //here goes private members when working with class //and public when working with structs public: //here goes public members protected: //here goes protected private: //here goes private public: //here goes public again }; </code></pre> <p>Ordering of members declaration is actually code policy question. For example, <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Access_Control" rel="nofollow">google style guide</a> recommends to put all <code>public</code> members before <code>private</code>.</p> <p>About hiding function members (not necessary private). You actually can't hide function member declaration, but there are several ways to "hide" implementation, but I am not sure that it's the definition of hiding you are talking about. But you can check <a href="http://en.wikibooks.org/wiki/C++_Programming/Idioms#Pointer_To_Implementation_.28pImpl.29" rel="nofollow">PImpl</a> idiom. This requires understanding of pointers so I advice you to start with them first.</p> <p>Small code sample for working with pointer to string:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; class MyClass { public: std::string *pstr; }; int main() { std::string str("test"); MyClass myObj; myObj.pstr = &amp;str; std::cout &lt;&lt; myObj.pstr-&gt;c_str() &lt;&lt; std::endl; } </code></pre>
    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. 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