title: GO - How does an implicit method work?
body: <blockquote>
    <p>In GO, I learnt that, </p>
    
    <p>1)</p>
    
    <p>Programmer can only define methods on named types(<code>X</code>) or pointer(<code>*X</code>) to named types</p>
    
    <p>2)</p>
    
    <p>An explicit method definition for type <code>X</code> implicitly defines the same method for type <code>*X</code> and <em>vice versa</em>, so, my understanding is, If I declare, </p>
  
  <pre><code>func (c Cat) foo(){
    //do stuff_
  } 
  </code></pre>
    
    <p>and declare,</p>
  
  <pre><code>func (c *Cat) foo(){
    // do stuff_
  }
  </code></pre>
    
    <p>then GO compiler gives, </p>
    
    <p><code>Compile error: method re-declared</code> </p>
    
    <p>which indicates that, pointer method is implicitly defined and <em>vice versa</em></p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p>With the given named type(<code>Cat</code>),</p>
  
  <pre><code>type Cat struct{
    Name string
    Age int
    Children []Cat
    Mother *Cat
  } 
  </code></pre>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p><strong>Scenario 1</strong></p>
    
    <p>Method(<code>foo</code>) defined on a named type(<code>Cat</code>), by programmer,</p>
  
  <pre><code>func (c Cat) foo(){
     // do stuff....
  }
  </code></pre>
    
    <p>that implicitly defines method(<code>foo</code>) on pointer(<code>*Cat</code>) to named type, by GO compiler, that looks like,</p>
  
  <pre><code>func (c *Cat) foo(){
     // do stuff....
  }
  </code></pre>
    
    <p>On creating variables of named type(<code>Cat</code>)</p>
  
  <pre><code>var c Cat
  var p *Cat = &amp;c
  </code></pre>
    
    <p><code>c.foo()</code> has the method defined by programmer.</p>
    
    <p><strong>Question 1:</strong></p>
    
    <p>On invoking <code>p.foo()</code>, does implicit pointer method receive the pointer(<code>p</code>)?</p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p><strong>Scenario 2</strong></p>
    
    <p>Method(<code>foo</code>) defined on a pointer(<code>*Cat</code>) to named type, by the programmer,</p>
  
  <pre><code>func (c *Cat) foo(){
     // do stuff....
    }
  </code></pre>
    
    <p>that implicitly defines method(<code>foo</code>) on named type(<code>Cat</code>), by the GO compiler, that looks like,</p>
  
  <pre><code>func (c Cat) foo(){
     // do stuff....
    }
  </code></pre>
    
    <p>On creating variables of named type(<code>Cat</code>)</p>
  
  <pre><code>var c Cat
  var p *Cat = &amp;c
  </code></pre>
    
    <p><code>p.foo()</code> has method defined by programmer(above).</p>
    
    <p><strong>Question 2:</strong></p>
    
    <p>On invoking <code>c.foo()</code>, does the implicit non-pointer method receive the value <code>c</code>?</p>
  </blockquote>