Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8073749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:26:00+00:00 2026-06-05T14:26:00+00:00

This linker error is in the main.cpp and is in the foreach.h class. Both

  • 0

This linker error is in the main.cpp and is in the foreach.h class. Both the constructor and deconstructor is tagged as an error.

LNK2019: unresolved external symbol

“public: __thiscall FE_Iterator::~FE_Iterator(void)” referenced in function “public: __thiscall Set,class std::allocator > >::Iterator::~Iterator(void)”

“public: __thiscall FE_Iterator::FE_Iterator(void)” referenced in function “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

main.cpp

#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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:26:03+00:00Added an answer on June 5, 2026 at 2:26 pm

    So this is a weird coincidence, but I worked with Eric Roberts on an updated version of the foreach code that doesn’t require a separate .cpp file. The new version of the file is right here, and this should compile without any linker errors:

    #ifndef Foreach_Included
    #define Foreach_Included
    
    #include <iterator>
    #include <map>
    #include <cstddef>
    #include <cstring>
    
    /* These #includes are for files that contain "in" as a token */
    
    #include <ios>
    #include <fstream>
    #include <sstream>
    using namespace std;
    
    /* 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;
    
    /* Private implementation namespace */
    
    namespace _fe {
       struct Range {
          virtual ~Range() { };
       };
    
       template <typename T>
       struct ArrayRange : Range {
          ArrayRange(const T *begin, const T *end) : iter(begin), end(end) { }
          const T *iter;
          const T *end;
       };
    
       template <typename CType>
       struct CRange : Range {
          CRange(const CType& c) :
             cont(c), iter(cont.begin()), end(cont.end()) { }
          CType cont;
          typename CType::iterator iter, end;
       };
    
       template <typename KT, typename VT, typename CT, typename AT>
       struct MapRange : Range {
          MapRange(const map<KT,VT,CT,AT> & c) :
             cont(c), iter(cont.begin()), end(cont.end()) { }
          map<KT,VT,CT,AT> cont;
          typename map<KT,VT,CT,AT>::iterator iter, end;
       };
    
    /*
     * The State struct glues together all of these pieces and
     * stores all of the information throughout the loops.
     */
    
       struct State {
          State() : state(0), itr(NULL) { }
          ~State() { delete itr; }
          int state;
          Range *itr;
       };
    
    /* General hook function */
    
       template <typename DowncastType, typename ValueType>
       ValueType HookImpl(State& fe) {
          DowncastType *ip = (DowncastType *) fe.itr;
          if (ip->iter == ip->end) {
             fe.state = 2;
             return ValueType();
          }
          fe.state = 1;
          ValueType vp = *ip->iter;     /* Subtle implementation note:    */
          ++ip->iter;                   /* Using *ip->iter++ here would   */
          return vp;                    /* require copying the iterator.  */
       }
    
    /* Foreach implementation for containers */
    
       template <typename CType>
       CRange<CType> *Init(State & fe, const CType & collection) {
          fe.itr = new CRange<CType>(collection);
          return (CRange<CType>*) fe.itr;
       }
    
       template <typename CType>
       typename iterator_traits<typename CType::iterator>::value_type
       Hook(State & fe, CRange<CType> *) {
          return HookImpl<CRange<CType>,
             typename iterator_traits<typename CType::iterator>::value_type>(fe);
       }
    
    /* For maps */
    
       template <typename K, typename V, typename C, typename A>
       MapRange<K,V,C,A> *Init(State & fe, const map<K,V,C,A> & collection) {
          fe.itr = new MapRange<K,V,C,A>(collection);
          return (MapRange<K,V,C,A>*) fe.itr;
       }
    
       template <typename DowncastType, typename ValueType>
       ValueType MapHookImpl(State & fe) {
          DowncastType *ip = (DowncastType *) fe.itr;
              if (ip->iter == ip->end) {
             fe.state = 2;
             return ValueType();
          }
          fe.state = 1;
          ValueType key = ip->iter->first;
          ++ip->iter;
          return key;
       }
    
       template <typename K, typename V, typename C, typename A>
       K Hook(State & fe, MapRange<K,V,C,A> *) {
          return MapHookImpl<MapRange<K,V,C,A>,K>(fe);
       }
    
    /* For C strings */
    
       template <size_t n>
       ArrayRange<char> *Init(State & fe, char (&str)[n]) {
          fe.itr = new ArrayRange<char>(str, str + strlen(str));
          return (ArrayRange<char>*) fe.itr;
       }
    
       template <size_t n>
       ArrayRange<char> *Init(State & fe, const char (&str)[n]) {
          fe.itr = new ArrayRange<char>(str, str + strlen(str));
          return (ArrayRange<char>*) fe.itr;
       }
    
    /* For arrays */
    
       template <typename T, size_t n>
       ArrayRange<T> *Init(State & fe, T (&arr)[n]) {
          fe.itr = new ArrayRange<T>(arr, arr + n);
          return (ArrayRange<T>*) fe.itr;
       }
    
       template <typename T, size_t n>
       ArrayRange<T> *Init(State & fe, const T (&arr)[n]) {
          fe.itr = new ArrayRange<T>(arr, arr + n);
          return (ArrayRange<T>*) fe.itr;
       }
    
       template <typename T>
       T Hook(State& fe, ArrayRange<T>*) {
          return HookImpl<ArrayRange<T>, T>(fe);
       }
    
    }
    
    /* The actual foreach and in macros */
    
    #define foreach(arg) \
       for (_fe::State _fe; _fe.state < 2; ) \
          for (arg)); _fe.state++ == 1; _fe.state = 0)
    
    #define in = _fe::Hook(_fe, _fe.state != 0 ? NULL : _fe::Init(_fe,
    
    #endif
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I'm getting a linker error LNK2019: unresolved external symbol when trying to use
I have been getting this error: 'unresolved external symbol main referenced in function _
I have the following error: LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
Linker Error: $ make g++ -Wall -g main.cpp SDL_Helpers.cpp Game.cpp DrawableObject.cpp `sdl-config --cflags --libs`
Im getting this linker error that won't let me compile. It only happens on
relocation truncated to fit: R_X86_64_PC32 against `.bss' I'm getting this linker error in g++
Unlike this question: Linker Error while building application using Boost Asio in Visual Studio
Why does the following code not give me a duplicate symbol linker error for
I am in linux. My Makefile file is this main2: main.cpp g++ -c $(LIBS)
I am baffled by the linker error when using the following code: // static_const.cpp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.