title: Error: Cannot call member function without object
body: <p>I'm having a problem when compiling this code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class Class1
  {   
      public:
          string m_Ime;
          Class1(const string ime);
  };
  
  Class1::Class1(string const ime):
      m_Ime(ime)
  {}
  
  class Class2
  {
      public:
          vector &lt;Class1&gt; m_Class1;
          Class2(int mesta);
          void RollCall();
          void Add(const Class1&amp; aClass1);
  };
  
  Class2::Class2(int mesta)
  {
      m_Class1.reserve(mesta);
  }
  
  void Class2::RollCall()
  {
      for(int x = 0; x &lt; m_Class1.size(); x++){
          cout &lt;&lt; m_Class1[x].m_Ime &lt;&lt; endl;
      }
      
  }
  
  void Class2::Add(const Class1&amp; aClass1)
  {
      m_Class1.push_back(aClass1);
  }
  
  int main(){
      Class2 skupina (3);
      
      Class2::Add(Class1 (&quot;Prvi&quot;));
      Class2::Add(Class1 (&quot;Drugi&quot;));
      Class2::Add(Class1 (&quot;Tretji&quot;));
      
      skupina.RollCall();
      
      return 0;
  }
  </code></pre>
  <p>It's nothing more than me trying to learn the basics of aggregation. However when trying to compile the code, it gives me the following errors:</p>
  <blockquote>
  <p>In function 'int main()':</p>
  <p>46 29 [Error] cannot call member function 'void Class2::Add(const Class1&amp;)' without object</p>
  <p>47 30 [Error] cannot call member function 'void Class2::Add(const Class1&amp;)' without object</p>
  <p>48 31 [Error] cannot call member function 'void Class2::Add(const Class1&amp;)' without object</p>
  </blockquote>
  <p>Even if I instantiate 3 objects of the type <code>Class1</code> and then call the <code>Add</code> function with them as arguments, the same error persists.</p>