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

  • Home
  • SEARCH
  • 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 8960279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:37:43+00:00 2026-06-15T15:37:43+00:00

I am trying to simulate Conway’s game of life using an implementation file I

  • 0

I am trying to simulate Conway’s game of life using an implementation file I created, I have made good progress but unfortunately I am getting an error which confuses me. I think the problem is ignorance on my part of how to properly code templated functions, anyways this is my implementation file:

#include <list>

#ifndef HashTable_h
#define HashTable_h

using namespace std;

#define HASHTABLE_CAPACITY 1009

template <class DataType>
class HashTable
{
  public:
    HashTable(); // constructor
    bool insert(DataType &a); // insert function for inserting value of dataType into table
    bool retrieve(DataType &a); // retrieve function for retrieving value from table
    bool replace(DataType &a); // function for replacing the value from the table with the parameter
    bool remove(DataType& a);//removed function written and checked
    //int getSizeOf() const;
    void clear(); // for clearing the table
    int size() const;

  private:
    list<DataType> table[HASHTABLE_CAPACITY]; // static array
    int count;
    int currentIndex;
    typename list<DataType>::const_iterator it;
};

// constructor
template <class DataType>
HashTable<DataType>::HashTable()
{
  list<DataType> table[HASHTABLE_CAPACITY];
  count = 0;
  currentIndex = -1;
}

// retrieve function
template <class DataType>
bool HashTable<DataType>::retrieve(DataType &a)
{
  // get wrapped index
  int wrappedIndex = a.hashCode() % HASHTABLE_CAPACITY;
  if (wrappedIndex < 0) wrappedIndex = wrappedIndex + HASHTABLE_CAPACITY;

  // if the array location isn't occupied, fail
  if (wrappedIndex < 0 || wrappedIndex >= HASHTABLE_CAPACITY || table[wrappedIndex].empty()) return false;

  // iterator for traversing table values
  typename list<DataType>::const_iterator it; 

  // if the keys match then replace the data
  // if a collision occurs then return false
  it = find(table[wrappedIndex].begin(), table[wrappedIndex].end(), a);
  if(it == table[wrappedIndex].end()) 
    return false; 
  a = *it;

  return true;
}

// overloaded operator function

// function for inserting values
template <class DataType>
bool HashTable<DataType>::insert(DataType &value)
{
  // get wrapped index
  int wrappedIndex = value.hashCode() % HASHTABLE_CAPACITY;
  if (wrappedIndex < 0) wrappedIndex = wrappedIndex + HASHTABLE_CAPACITY;

  // iterator for traversing values in table
  typename list<DataType>::iterator it;

  // if array location is not "occupied", copy into array
  // else if keys match, replace the data
  if (table[wrappedIndex].empty())
  {
    table[wrappedIndex].push_back(value);
    count++;
    return true;
  }
  else
  {
    it = find(table[wrappedIndex].begin(), table[wrappedIndex].end(), value); 
    if (it != table[wrappedIndex].end()) *it = value;
    else {table[wrappedIndex].push_back(value); count++;}
  }

  return true;
}

// function for replacing values
template <class DataType>
bool HashTable<DataType>::replace(DataType &value)
{
  // get wrapped index
  int wrappedIndex = value.hashCode() % HASHTABLE_CAPACITY;
  if (wrappedIndex < 0) wrappedIndex = wrappedIndex + HASHTABLE_CAPACITY;

  if(table[wrappedIndex].empty()) return false;

  // iterator for traversing the values in table
  typename list<DataType>::const_iterator it;

  it = find(table[wrappedIndex].begin(), table[wrappedIndex].end(), value);
  if(it == table[wrappedIndex].end()) return false;

  value = *it;
  table[wrappedIndex].erase(it);
  count--;

  return true;
}

template <class DataType>
bool HashTable<DataType>::remove(DataType &value)
{
  // get wrapped index
  int wrappedIndex = value.hashCode() % HASHTABLE_CAPACITY;
  if (wrappedIndex < 0) wrappedIndex = wrappedIndex + HASHTABLE_CAPACITY;

  if(table[wrappedIndex].empty()) return false;

  // iterator for traversing the values in table
  typename list<DataType>::iterator it;

  // if array location is not "occupied", copy into array
  // else if keys match, remove the data
  it = find(table[wrappedIndex].begin(), table[wrappedIndex].end(), value);
  if(it == table[wrappedIndex].end()) return false;

  value = *it;
  table[wrappedIndex].erase(it);
  count--;

  return true;
}


// function for clearing the table of it's values
template <class DataType>
void HashTable<DataType>::clear()
{
  count = 0;
  currentIndex = -1;

  for(int i = 0; i < HASHTABLE_CAPACITY; i++) 
    if( !table[i].empty()) table[i].clear();
}

template <class DataType>
int HashTable<DataType>::size() const
{
  return count;
}

#endif

And this is the actual Game Of Life driver file:

// Lab 11b
#include <iostream>
using namespace std;

struct cell
{
  int value; // equal to 1, so 0,0 is not a blank
  int row; // any +/0/- value
  int col; // any +/0/- value

  bool operator==(const cell& c) const {return row == c.row && col == c.col;}
  bool operator<(const cell& c) const {return (1000000 * row + col) < (1000000 * c.row + c.col);}
  int hashCode() const {return 31 * row + col;}
};

#include "HashTable.h"
HashTable<cell> grid;
HashTable<cell> newGrid;

const int MINROW = -25;
const int MAXROW = 25;
const int MINCOL = -35;
const int MAXCOL = 35;

int neighborCount(int row, int col)
{
  cell temp;
  int count = 0;
  for (temp.row = row - 1; temp.row <= row + 1; temp.row++)
    for (temp.col = col - 1; temp.col <= col + 1; temp.col++)
      if (temp.row != row || temp.col != col)
        if (grid.retrieve(temp))
          ++count;
  return count;
}

void initialize()
{
  cout << "List the coordinates for living cells.\n";
  cout << "Terminate the list with a special pair -1 -1\n";

  cell temp;
  while (true)
  {
    cin >> temp.row >> temp.col;
    if (temp.row == -1 && temp.col == -1) break;
    grid.insert(temp);
  }
  cin.ignore();
}

void print()
{
  cell temp = {1};
  cout << "\nThe current Life configuration is:\n";
  for (temp.row = MINROW; temp.row <= MAXROW; temp.row++)
  {
    for (temp.col = MINCOL; temp.col <= MAXCOL; temp.col++)
      if (grid.retrieve(temp)) 
        cout << '*';
      else
        cout << ' ';
    cout << endl;
  }
  cout << endl;
}

void update()
{
  cell temp = {1};
  newGrid.clear();
  for (temp.row = MINROW; temp.row <= MAXROW; temp.row++)
    for (temp.col = MINCOL; temp.col <= MAXCOL; temp.col++)
      switch (neighborCount(temp.row, temp.col))
      {
        case 2:
          if (grid.retrieve(temp)) newGrid.insert(temp);
          break;
        case 3:
          newGrid.insert(temp);
          break;
      }

  grid = newGrid;    
};

int main()
{
  cout << "Welcome to Conway's game of Life\n";
  cout << "This game uses a grid in which\n";
  cout << "each cell can either be occupied by an organism or not.\n";
  cout << "The occupied cells change from generation to generation\n";
  cout << "according to the number of neighboring cells which are alive.\n";

  initialize();
  print();

  for (int i = 1; grid.size(); i++)
  {
    cout << "Generation " << i << ". Press ENTER to continue, X-ENTER to quit...\n";
    if (cin.get() > 31) break;
    update();
    print();
  }
  return 0;
}

When I try to compile these files I get this error:

In file included from GameOfLife.cpp:16:
HashTable.h: In member function ‘bool HashTable<DataType>::retrieve(DataType&) [with DataType = cell]’:
GameOfLife.cpp:32:   instantiated from here
HashTable.h:74: error: no matching function for call to ‘find(std::_List_iterator<cell>, std::_List_iterator<cell>, cell&)’
HashTable.h: In member function ‘bool HashTable<DataType>::insert(DataType&) [with DataType = cell]’:
GameOfLife.cpp:47:   instantiated from here
HashTable.h:117: error: no matching function for call to ‘find(std::_List_iterator<cell>, std::_List_iterator<cell>, cell&)’

What could be the issue here?

  • 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-15T15:37:44+00:00Added an answer on June 15, 2026 at 3:37 pm

    You need to #include <algorithm> to get std::find. This is presumably what you want to use when you call find. You should avoid using namespace std, specially in headers.

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

Sidebar

Related Questions

I'm trying to simulate a token ring using python with sockets, but I have
I'm trying to simulate some code that I have working with SQL but using
I am trying to simulate an asynchronous file upload using an iframe. Here is
I am trying to simulate inheritance in C, so I created a C file
I'm trying to simulate a particle system using OpenGl but I can't get it
I am trying to simulate an intersection using threads and mutex locks. I have
I am trying to simulate the scoring of a squash game using english rules.
I'm trying to simulate a working product and have created a PHP array of
I am trying to simulate linux command ls using linux api from c. Looking
I'm trying to simulate rotating box using Newton Physics and OpenGL. This is what

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.