-2

I am using Microsoft Visual Studio for this program, and it keeps throwing the following errors:

->error LNK2019: unresolved external symbol "public: virtual int __thiscall unorderedArrayListType::min(void)" (?min@unorderedArrayListType@@UAEHXZ) referenced in function _main   C:\Users\Emma.Barrett\Desktop\School\c++\Programs\chapter12_exercise9\chapter12_exercise9\Source.obj    chapter12_exercise9

->error LNK2001: unresolved external symbol "public: virtual int __thiscall unorderedArrayListType::min(void)" (?min@unorderedArrayListType@@UAEHXZ)    C:\Users\Emma.Barrett\Desktop\School\c++\Programs\chapter12_exercise9\chapter12_exercise9\unorderedArrayListTypeImp.obj chapter12_exercise9

->error LNK1120: 1 unresolved externals C:\Users\Emma.Barrett\Desktop\School\c++\Programs\chapter12_exercise9\Debug\chapter12_exercise9.exe chapter12_exercise9

My program was compiling fine until I added the min() function to the unorderedArrayListTypeImp.cpp and arrayListTypeImp.cpp. I am relatively new to C++, so it's probably a stupid fix, but I can't seem to figure it out.

Here is the unorderedArrayListTypeImp.cpp:

#include "unorderedArrayListType.h"
#include <string>

void unorderedArrayListType::insertAt(int location, int insertItem)
{
    if (location < 0 || location >= maxSize)
    {
        cout << "The position of the item to be inserted is out of range"
            << endl;
    }
    else if (length >= maxSize)
    {
        cout << "Cannot insert in a full list"
            << endl;
    }
    else
    {
        for (int i = length; i > location; i--)
        {
            list[i] = list[i - 1];
        }
        list[location] = insertItem;

        length++;
    }
}

void unorderedArrayListType::insertEnd(int insertItem)
{
    if (length >= maxSize)
    {
        cout << "Cannot insert in a full list." << endl;
    }
    else
    {
        list[length] = insertItem;
        length++;
    }
}

int unorderedArrayListType::seqSearch(int searchItem) const
{
    int loc;
    bool found = false;

    loc = 0;

    while (loc < length && !found)
    {
        if (list[loc] == searchItem)
        {
            found = true;
        }
        else
        {
            loc++;
        }
    }
    if (found)
    {
        return loc;
    }
    else
    {
        return -1;
    }
}

void unorderedArrayListType::remove(int removeItem)
{
    int loc;

    if (length == 0)
    {
        cout << "Cannot delete from an empty list." << endl;
    }
    else
    {
        loc = seqSearch(removeItem);
        if (loc != -1)
        {
            removeAt(loc);
        }
        else
        {
            cout << "The item to be deleted is not in the list."
                << endl;
        }
    }
}

void unorderedArrayListType::replaceAt(int location, int repItem)
{
    if (location < 0 || location >= length)
    {
        cout << "The location of the item to be replaced is out of range."
            << endl;
    }
    else
    {
        list[location] = repItem;
    }
}

int min()
{
    arrayListType:min();
    return 0;
}

unorderedArrayListType::unorderedArrayListType(int size)
    :arrayListType(size)
{

}

Here is the arrayListTypeImp.cpp:

#include "arrayListType.h"
#include <iostream>
#include <string>
using namespace std;

bool arrayListType::isEmpty() const
{
    return (length == 0);
}

bool arrayListType::isFull() const
{
    return (length == maxSize);
}

int arrayListType::listSize() const
{
    return length;
}

int arrayListType::maxListSize() const
{
    return maxSize;
}
void arrayListType::print() const
{
    for (int i = 0; i < length; i++)
    {
        cout << list[i] << " ";
    }
    cout << endl;
}

bool arrayListType::isItemAtEqual(int location, int item) const
{
    if (location < 0 || location >= length)
    {
        cout << "The location of the item to be removed is out of range."
            << endl;
        return false;
    }
    else
        return (list[location] == item);
}

void arrayListType::removeAt(int location)
{
    if (location < 0 || location >= length)
    {
        cout << "The location of the item to be removed is out of range"
            << endl;
    }
    else
    {
        for (int i = location; i < length - 1; i++)
        {
            list[i] = list[i + 1];
        }
        length--;
    }
}

void arrayListType::retrieveAt(int location, int& retItem) const
{
    if (location < 0 || location >= length)
    {
        cout << "The location of the item to be retrieved is out of range"
            << endl;
    }
    else
    {
        retItem = list[location];
    }
}

void arrayListType::clearList()
{
    length = 0;
}

int arrayListType::min()
{
    int smallest = list[0];
    for (int i = 0; i < length; i++)
    {
        if (list[i] < smallest)
        {
            return i;
        }
    }
}

arrayListType::arrayListType(int size)
{
    if (size <= 0)
    {
        cout << "The array size must be positive. Creating an array of the size 100."
            << endl;
        maxSize = 100;
    }
    else
    {
        maxSize = size;
    }
    length = 0;
    list = new int[maxSize];
}

arrayListType::~arrayListType()
{
    delete[] list;
}

arrayListType::arrayListType(const arrayListType& otherList)
{
    maxSize = otherList.maxSize;
    length = otherList.length;

    list = new int[maxSize]; //create the array

    for (int j = 0; j < length; j++)
    {
        list[j] = otherList.list[j];
    }
}

Here is the source file:

#include <iostream>
#include "arrayListType.h"
#include "unorderedArrayListType.h"

using namespace std;

int main()
{
    unorderedArrayListType intList(25);

    int number;

    cout << "Enter 8 integers: ";

    for (int count = 0; count < 8; count++)
    {
        cin >> number;
        intList.insertEnd(number);
    }

    cout << endl;
    cout << "intList: ";
    intList.print();
    cout << endl;

    cout << "The smallest number in intList: "
        << intList.min() << endl;
    system("pause");
    return 0;
}
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
Emma Barrett
  • 83
  • 1
  • 10

1 Answers1

0

You forgot the unorderedArrayListType:: for min in the .cpp.

int unorderedArrayListType::min()

Without it, instead of defining the function, you create a new non-member function. The linker then tries to find the implementation of the member function min that was declared in the header, but cannot.

Weak to Enuma Elish
  • 4,622
  • 3
  • 24
  • 36