title: Note: while compiling class template member function C++
body: <p>Why is VS giving me this error? I am quite new to OOP and Templates in C++ and I am trying to write simple Stack implementation using these techniques. I tried to google it but I did not find anything useful.</p>
  
  <p>Code:</p>
  
  <pre><code>#ifndef _STACK
  #define _STACK
  template &lt;class T&gt;
  class Stack {
  
      public:
          Stack();
          Stack(const int &amp;num);
          Stack(const Stack&lt;T&gt; &amp;obj);
          Stack&amp; operator=(const Stack&lt;T&gt; &amp;obj);
          ~Stack();
  
      private:
          T * buffer;
          unsigned int actualSize;
          unsigned int maxSize;
  };
  template &lt;class T&gt;
  Stack&lt;T&gt;::Stack() : maxSize(5), actualSize(0), buffer(new T[5]) {};
  
  template &lt;class T&gt;
  Stack&lt;T&gt;::Stack(const int &amp;num) : maxSize(num), actualSize(num), buffer(new T[num]) {};
  
  template &lt;class T&gt;
  Stack&lt;T&gt;::Stack(const Stack&lt;T&gt; &amp;obj) {
      this-&gt;actualSize = obj.actualSize;
      this-&gt;maxSize = obj.maxSize;
      std::copy(obj.buffer, obj.buffer + obj.actualSize, this-&gt;buffer);
  }
  
  template &lt;class T&gt;
  Stack&lt;T&gt;&amp;  Stack&lt;T&gt;::operator=(const Stack&lt;T&gt; &amp;obj) {
      T * temp = new T[obj.actualSize];
      std::copy(obj.buffer, obj.buffer + obj.actualSize, temp);
      this-&gt;actualSize = obj.actualSize;
      this-&gt;maxSize = obj.maxSize;
      delete[] buffer;
      buffer = temp;
      return *this;
  }
  
  template &lt;class T&gt;
  Stack&lt;T&gt;::~Stack() {
      delete[] buffer;
  }
  
  #endif
  </code></pre>
  
  <p>Full build log - obviously there is a problem with std::copy :</p>
  
  <pre><code>1&gt;------ Build started: Project: Stack, Configuration: Debug Win32 ------
  1&gt;main.cpp
  1&gt;c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\xutility(2483): warning C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
  1&gt;c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\xutility(2483): note: see declaration of 'std::copy::_Unchecked_iterators::_Deprecate'
  1&gt;c:\users\peter\documents\pb071hw\circle\stack\stack.h(34): note: see reference to function template instantiation '_OutIt std::copy&lt;T*,T*&gt;(_InIt,_InIt,_OutIt)' being compiled
  1&gt;        with
  1&gt;        [
  1&gt;            _OutIt=int *,
  1&gt;            T=int,
  1&gt;            _InIt=int *
  1&gt;        ]
  1&gt;c:\users\peter\documents\pb071hw\circle\stack\stack.h(32): note: while compiling class template member function 'Stack&lt;int&gt; &amp;Stack&lt;int&gt;::operator =(const Stack&lt;int&gt; &amp;)'
  1&gt;c:\users\peter\documents\pb071hw\circle\stack\main.cpp(13): note: see reference to function template instantiation 'Stack&lt;int&gt; &amp;Stack&lt;int&gt;::operator =(const Stack&lt;int&gt; &amp;)' being compiled
  1&gt;c:\users\peter\documents\pb071hw\circle\stack\main.cpp(10): note: see reference to class template instantiation 'Stack&lt;int&gt;' being compiled
  1&gt;Stack.vcxproj -&gt; 
  </code></pre>