title: C++: How does a getter return a pointer to a dynamically allocated array without giving direct acces to it?
body: <p>So the question is: </p>
  
  <p>If I have a program something like: </p>
  
  <pre><code>class Ticket
  {
   private: 
      char* concertName;
   public:
      Ticket(char* name="Concert");
      char* getConcertName();
  }
  int main()
  {
     char* test;
     Ticket t1;
     test=t1.getConcertName();
     test[1]='A';     
  }
  Ticket::Ticket(char* name)
  {
     this-&gt;concertName=new char[strlen(Concert)+1];
     strcpy(this-&gt;concertName,name);
  }
  Ticket::getConcertName()
  {
    return this-&gt;concertName;
  }
  </code></pre>
  
  <p>What would the getter return? My intuition says that it returns the pointer to the first element of the memory block that I allocated earlier for concertName, and so I can change the array's values without using the setter, directly from main like I did in the example.</p>
  
  <p>It works to change it, but the idea of the private area is for restricting the access from outside the object to it's attributes if a setter or a getter isn't used.</p>
  
  <p>What if we had a static field like: static unsigned int* arrayI; and a static method that worked like a getter returning the value from arrayI?</p>