This program shows me some unknown linker error. What could be wrong?
Error:
Undefined symbols for architecture x86_64:
"totalIncome(Husband<int>, Wife<int>)", referenced from:
_main in main.cpp.o
#include <iostream>
using namespace std;
template<typename T> class Wife; // Forward declaration of template class : Wife
template<typename T>
class Husband{
friend void totalIncome(Husband<T> hobj, Wife<T> wobj);
public:
Husband() = default;
Husband(T new_salary): salary{new_salary} {}
private:
T salary;
};
template<typename T>
class Wife{
friend void totalIncome(Husband<T> hobj, Wife<T> wobj);
public:
Wife() = default;
Wife(T new_salary): salary{new_salary} {}
private:
T salary;
};
template<typename T> void totalIncome(Husband<T> hobj, Wife<T> wobj)
{
cout << "Total Income of Husband & Wife: ";
cout << hobj.salary + wobj.salary;
}
int main()
{
Husband<int> h(40000);
Wife<int> w(90000);
totalIncome(h, w);
return 0;
}