I'm getting "Unresolved external symbols" for the following code:
template <int n> class Fibo
{
private:
int pre, cur, next, tmp;
public:
Fibo() : pre(1), cur(1), next(2), tmp(0) {}
int get()
{
if(n == 0 || n == 1) return 1;
for(int i = 2; i < n; ++i)
{
next = pre + cur;
tmp = cur;
cur = next;
pre = tmp;
} return pre + cur;
}
friend ostream& operator<< (ostream& out, Fibo<n>& f);
};
template<int n>
ostream& operator<< (ostream& out, Fibo<n>& f)
{
out << f.get();
return out;
}
int main()
{
Fibo<5> a;
cout << a << endl;
cin.get();
}
I get this compilation error when I'm trying to print a
:
cout << a << endl;
. When I'm printing "normaly", i.e. cout << a.get() << endl
, no errors popped.
I know that Unresolved external symbols
error are associated with declared function that didn't implemented. is that the case in my code? I can't find it.