title: How to declare a friend function of a template inside a class and implement this friend function ouside class?
body: <p>Well, I'm trying to implement the copy_and_swap idiom on my first Stack in C++, for that I need to create a swap function and this swap function needs to be a friend function, I tried to do it by this way:</p>
  
  <pre><code>template &lt;class T&gt;
  class Stack {
      private:
          int top;
          T* a;
          int MAX;
  
      public:
          Stack(int MAX);
          Stack(Stack&lt;T&gt;&amp; s);
          bool push(T x);
          bool pop();
          T peek();
          bool isEmpty();
          friend void swap(Stack&lt;T&gt;&amp; f, Stack&lt;T&gt;&amp; s);
          ~Stack();
  };
  
  template &lt;class T&gt;
  void Stack&lt;T&gt;::swap(Stack&lt;T&gt;&amp; f, Stack&lt;T&gt;&amp; s){
  //I will put something where yet.
  }
  </code></pre>
  
  <p>But, the VSCode says this about the swap function: class model "Stack " does not have a "swap" member (I translate for English, my VSCode runs in Portuguese).</p>
  
  <p>How I can do that without receiving this error?</p>