#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include "FilmScore.h"
#include "HashedDictionary.h"
using namespace std;
string getFileName();
bool createRecord( const FilmScore & newRecord, const string & inputLine );
void eraseTrailingSpaces( string & input );
void extractData( string & composer, string & filmTitle, string & label, string & catalogNum, string & recordingYear, string & releaseYear, const string & inputLine );
void pause();
template <typename T>
void readFile( vector<T> & p_records );
template <typename T>
bool isDuplicate( const vector<T> & records, const T & newRecord );
template <typename T>
void displayVector( const vector<T> & vec );
const unsigned COMPOSER_FIELD_LENGTH = 24,
FILM_TITLE_FIELD_LENGTH = 40,
LABEL_FIELD_LENGTH = 16,
CATALOG_NUM_FIELD_LENGTH = 24,
RECORDING_YEAR_FIELD_LENGTH = 8,
CD_RELEASE_YEAR_FIELD_LENGTH = 4;
const unsigned COMPOSER_BEGIN = 0,
FILM_TITLE_BEGIN = COMPOSER_FIELD_LENGTH,
LABEL_BEGIN = FILM_TITLE_BEGIN + FILM_TITLE_FIELD_LENGTH,
CATALOG_NUM_BEGIN = LABEL_BEGIN + LABEL_FIELD_LENGTH,
RECORDING_YEAR_BEGIN = CATALOG_NUM_BEGIN + CATALOG_NUM_FIELD_LENGTH,
CD_RELEASE_YEAR_BEGIN = RECORDING_YEAR_BEGIN + RECORDING_YEAR_FIELD_LENGTH;
const string DEFAULT_FILE_NAME = "Soundtrack.txt";
template <class ItemType>
ostream& operator<<( ostream & out, const HashedDictionary<ItemType> & table )
{
for ( unsigned i = 0; i < table.hashTableSize; i++ )
if ( table.hashTable[i] != NULL )
table.displayChain( out, table.hashTable[i] );
return out;
}
int main()
{
vector<FilmScore> records;
readFile( records );
pause();
HashedDictionary<FilmScore> hashTable( records.size() * 3 );
// load the films into the hash table:
for ( size_t i = 0; i < records.size(); i++ )
hashTable.add( records[i] );
try
{
cout << "Get item with key \"FSMBox 03 Disc 8\":\n";
cout << hashTable.getItem( static_cast<string>( "FSMBox 03 Disc 8" ) );
}
catch ( PrecondViolatedExcep e )
{
cout << e.what();
}
cout << endl << endl;
try
{
cout << "Get item with key \"FSMBox 07 Disc 8\":\n";
cout << hashTable.getItem( static_cast<string>( "FSMBox 07 Disc 8" ) );
}
catch ( PrecondViolatedExcep e )
{
cout << e.what();
}
cout << endl << endl;
pause();
cout << "Listing all items in the has table: (There are " << hashTable.getItemCount() << " items in the table)\n\n";
cout << hashTable;
return 0;
}
错误:
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 HashedDictionary<class FilmScore> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$HashedDictionary@VFilmScore@@@@@Z) referenced in function __catch$_main$0
1>C:\Users\user\Desktop\CS M20A\Topic E2 Project\Debug\Topic E2 Project.exe : fatal error LNK1120: 1 unresolved externals
我查看了其他有这个错误的人的问题,看起来它与没有定义的函数有关,但在这种情况下,运算符&lt;&lt;在main()上面定义。我不知道问题是什么。