Hello all:
I have been working on a project in my spare time and have been unable to find the source of a linker error after a few hours.
First, the overloaded output operator in this class is throwing the following error when attempting to use the << operator:
Code:
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > &
__cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class CayleyTable<int> &)"
(??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$CayleyTable@H@@@Z)
referenced in function _main
1>C:\Documents and Settings\asdfg\My Documents\Visual Studio 2005\Projects\test2\Debug\test2.exe :
fatal error LNK1120: 1 unresolved externals
This is with the following class:
Code:
template <class ItemType>
class CayleyTable
{
public:
CayleyTable();
CayleyTable(int NumOfElements);
CayleyTable(CayleyTable<ItemType>& AnotherCayleyTable);
void SetNumberOfElements(int n);
void DefineCayleyTable(vector< vector<ItemType> >& ACayleyTable);
int NumberOfElements();
list< OrderedPair<int> >& FindIndices(ItemType Item);
//Post: returns a list of ordered pairs of integers representing the indices in
// which Item was found in the Cayley table
ItemType ReturnIndex(int i, int j);
//Post: returns the (i,j)th entry of the Cayley table
friend ostream& operator << (ostream& out, CayleyTable<ItemType>& TheTable);
private:
vector< vector<ItemType> > TheCayleyTable;
};
I defined the output operator for this class as follows:
Code:
template <class ItemType>
ostream& operator << (ostream& out, CayleyTable<ItemType>& TheTable)
{
for (int i = 0; i < TheTable.TheCayleyTable.size(); i++)
{
for (int j = 0; j < TheTable.TheCayleyTable.size(); j++)
{
out << TheTable.TheCayleyTable[i][j] << " ";
}
out << endl;
}
return out;
}
Thanks for any help!