此链接器错误位于 main.cpp 和 foreach.h 类中。构造函数和解构函数都被标记为错误。
LNK2019:未解析的外部符号
“public: __thiscall FE_Iterator::~FE_Iterator(void)”在函数“public: __thiscall Set,class std::allocator >>::Iterator::~Iterator(void)”中引用
“public: __thiscall FE_Iterator::FE_Iterator(void)”在函数“private: __thiscall Set,class std::allocator > >::Iterator::Iterator(class Set,class std::allocator > > *)”中引用
foreach.h
/*
* File: foreach.h
* Last modified on Thu Jun 11 12:04:09 2009 by eroberts
* -----------------------------------------------------
* This interface defines the foreach keyword, which is used to
* simplify iteration. All iterable classes import this interface,
* so clients never need to do so explicitly.
*/
#ifndef _foreach_h
#define _foreach_h
#include "genlib.h"
/* These #includes are for files that contain "in" as a token */
#include <ios>
#include <fstream>
#include <sstream>
/* Redefine the ios constants (one of which is "in") */
static const ios::openmode IOS_APP = ios::app;
static const ios::openmode IOS_ATE = ios::ate;
static const ios::openmode IOS_BINARY = ios::binary;
static const ios::openmode IOS_IN = ios::in;
static const ios::openmode IOS_OUT = ios::out;
static const ios::openmode IOS_TRUNC = ios::trunc;
/*
* Class: FE_Iterator
* ------------------
* This class is a base class for all Iterators that can work with
* the foreach construct. The only purpose of this class is to make
* it possible to freeing the iterators after they are no longer needed.
*
* Note: FE_Iterator is implemented in lexicon.cpp, which is the only
* iterable class that is not a template class.
*/
class FE_Iterator {
public:
FE_Iterator();
~FE_Iterator();
};
/*
* Class: FE_State
* ---------------
* This class is used to maintain the state of the foreach processing.
* The class itself is essentially private, but the implementations in
* the different classes use the fields directly.
*
* Note: FE_State is implemented in lexicon.cpp, which is the only
* iterable class that is not a template class.
*/
class FE_State {
public:
int state;
FE_Iterator *iter;
FE_State();
~FE_State();
};
/*
* Macro: foreach
* Usage: foreach (type var in collection) { . . . }
* -------------------------------------------------
* Provides a much simpler hook to the iterator facility.
*/
#define foreach(arg) \
for (FE_State _fe; _fe.state < 2; ) \
for (arg.foreachHook(_fe); _fe.state++ == 1; _fe.state = 0)
#define in =
#endif
主文件
#include "stdafx.h"
#include <cstdlib>
#include <string>
#include <iostream>
#include <set>
#include <fstream>
#include "genlib.h"
#include "strutils.h"
#include "simpio.h"
#include "set.h"
#include "lexicon.h"
#include "iterator.h"
#include "foreach.h"
using namespace std;
void PrintRegExpMatches(string exp, Set<string> & matches)
{
cout << "Activity codes that match " << exp << endl;
cout << "--------------------------------------" << endl;
Set<string>::Iterator it = matches.iterator();
while (it.hasNext()) cout << it.next() << endl;
void PrintCorrections(string seed, int editDistance,
Set<Lexicon::CorrectionT> & matches)
{
cout << "Activity codes that are within " << editDistance << " edits of " << seed << endl;
cout << "--------------------------------------" << endl;
Set<Lexicon::CorrectionT>::Iterator it = matches.iterator();
while (it.hasNext()) {
Lexicon::CorrectionT corr = it.next();
cout << corr.suggestedWord << " is a distance of " << corr.editDistance;
cout << " away." << endl;