I am getting a strange undefined reference to error for some of the methods in my ComplexNumber.cpp, I am very new to templates though : <p>Getting c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: main.o:main.cpp:(.text+0x2b): undefined reference to (<em>insert my methods in ComplexNumber.cpp</em>) when compiling using a makefile after the G++ main.o ComplexNumber.o -o output is being ran.</p>

<p>I have tried checking online for places I may have missed a  and used my other header files I have done in the past for reference to check for errors there, but I have had no luck. I am using cygdrive on windows to compile, but have also tried just using mingw on regular command prompt as well. </p>

<p>Header File:
'''''''''''''</p>

<pre><code>#include &lt;stdio.h&gt;


#ifndef COMPLEXNUMBER_H_
#define COMPLEXNUMBER_H_



template&lt;typename T&gt;

class ComplexNumber
{

    public:
        // a is a real number, b is a complex number
        T a;
        T b;
        ComplexNumber();
        ComplexNumber(T, T);
        void toString();
    ComplexNumber operator +(ComplexNumber&lt;T&gt;&amp; c);
    ComplexNumber operator *(ComplexNumber&lt;T&gt;&amp; c);
    bool operator ==(ComplexNumber&lt;T&gt;&amp; c);
};



#endif /* COMPLEXNUMBER_H_ */
</code></pre>

<p>''''''''''''''</p>

<p>ComplexNumber.cpp
''''''''''''''</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctime&gt;
#include "ComplexNumber.h"


using namespace std;


template &lt;typename T&gt;

    ComplexNumber&lt;T&gt;::ComplexNumber()
    {}
template &lt;typename T&gt;
ComplexNumber&lt;T&gt;::ComplexNumber(T a, T b)
{
    this-&gt;a = a;
    this-&gt;b = b;
}
template &lt;typename T&gt;
ComplexNumber&lt;T&gt; ComplexNumber&lt;T&gt;:: operator +(ComplexNumber&amp; c)
{
    ComplexNumber &lt;T&gt; temp;

    // adds the complex numbers, (a+bi) + (c+di) = (a+b) + i(c+d)
    temp.a = this-&gt;a + c.a;
    temp.b = this-&gt;b + c.b;
    return temp;
}
template &lt;typename T&gt;
ComplexNumber&lt;T&gt; ComplexNumber&lt;T&gt;:: operator *(ComplexNumber&amp; c)
{
    ComplexNumber&lt;T&gt; temp;

    // multiplies complex numbers, (a+bi) + (c+di) = (a*c-b*d) + i(a*d + b*c)
    temp.a = (this-&gt;a * c.a) - (temp.b * c.b);
    temp.b = (temp.a * c.b) + (temp.b * c.a);
    return temp;
}
template &lt;typename T&gt;
bool ComplexNumber&lt;T&gt;:: operator ==(ComplexNumber&lt;T&gt;&amp; c)
{
    ComplexNumber&lt;T&gt; temp;

    // compares complex numbers to see if they're equal, (a+bi) == (c+di) -&gt; if (a==c) &amp; (b==d)
    if (temp.a == c.a &amp;&amp; temp.b == c.b)
    {
        cout&lt;&lt; "The complex numbers are equal."&lt;&lt;endl;
        return true;
    }
    return false;
}
template &lt;typename T&gt;
void ComplexNumber&lt;T&gt;::toString()
{

    cout&lt;&lt; "("&lt;&lt; this-&gt;a&lt;&lt; " + "&lt;&lt; this-&gt;b&lt;&lt; "i)"&lt;&lt;endl;
}
</code></pre>

<p>MakeFile:
''''''''''''''</p>

<pre><code>all: ComplexNumber
ComplexNumber: main.o ComplexNumber.o
    g++ main.o ComplexNumber.o -o output
main.o: main.cpp
    g++ -c main.cpp
ComplexNumber.o: ComplexNumber.cpp
    g++ -c ComplexNumber.cpp
clean:
    rm *.o output
</code></pre>

<p>''''''''''''''</p>
