title: when a class element from array is modified, it behaves like it is a copy, not reference
body: <p>This is a simple thing that I'm not sure if it is possible in C++ like in some other languages. The thing behaves like it is a copy, but not the same object. I would expect that if this was struct, or some other value type - this would be expected behaviour, but for class, I expected this to behave like I'm looking at "reference", that is - the same object as is in array. What am I doing wrong? </p>
  
  <pre><code>// Example program
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  
  class someclass
  {
      public:        
      void setn(int n2);
      int n=10;
  };
  
  void someclass::setn(int n2){
      n=n2;
  };
  
  
  int main()
  {
    someclass moreofthem[5];   
    someclass my=moreofthem[1];  
    std::cout &lt;&lt; "start value: " &lt;&lt; my.n &lt;&lt; " as inital\n"; //10
    my.setn(2);  
    std::cout &lt;&lt; "new value: " &lt;&lt; my.n &lt;&lt; " as expected\n"; //2
    std::cout &lt;&lt; "value in list: " &lt;&lt; moreofthem[1].n &lt;&lt; " why?\n";  //10?
  
  }
  </code></pre>