0

I'm attempting to create a program that creates a Double Linked List. When I stopped working on it yesterday, no problems were present, but when I started working today, the following began popping up.

CODE: LNK2019 

DESCRIPTION: unresolved external symbol_WinMain@16 referenced in function "int_cdel invoke_main(void)" (?invoke_main@@YAHXZ) 

FILE: MSVCRTD.lib(exe_winmain.obj

LINE: 1

I have managed to narrow it down the source file it is in, so I will include the.cpp and.h file for it.

.h file

#ifndef DHSTRING_H
#define DHSTRING_H

#include <iostream>
#include <cctype>
#include <stdio.h>
#include <ctype.h>

using namespace std;

class DHString
{
public:
    DHString();
    DHString(const char* cstr);
    DHString(const DHString& mstr);
    ~DHString();

    DHString& operator=(const DHString& rhs);

    int length() const;
    int capacity() const;

    char operator[](int index);
    char at(int index);
    
    const char* c_str() const;

    friend istream& operator >>(istream& in, DHString &rhs);
    friend ostream& operator <<(ostream& out, const DHString& rhs);
    bool operator < (const DHString& rhs) const;
    bool operator > (const DHString& rhs) const;
    bool operator == (const DHString& rhs) const;
    DHString operator + (const DHString& rhs) const;

    static int getCurrentCount(); 
    static int getCreatedCount();

private: 
    char* str;
    int end;
    int cap = 20;
    static int currentCount;
    static int createdCount;
     
    int compareTo(const DHString& argStr)
    {
        int shortestLen = (end < argStr.end ? end : argStr.end);
        int dif;
        
        for (int i = 0; i <= shortestLen; ++i)
        {
            dif = tolower(str[i]) - tolower(argStr.str[i]);
            if (dif != 0)
            {
                return dif;
            }
        }
        return 0;
    }

};
#endif;

.cpp file

#include "DHString.h"

int DHString::currentCount = 0;
int DHString::createdCount = 0;

DHString::DHString()
{
    cap = 20;
    end = 0;
    str = new char[cap];
    str[end] = '\0';
    createdCount++;
    currentCount++;
}

DHString::DHString(const char* cstr)
{
    do
    {
        str[end] = cstr[end];
        end++;

        if (end == cap - 1)
        {
            cap = cap + 20;
        }

    } while (cstr[end] != '\0');
    str[end] = '\0';
}   

DHString::DHString(const DHString& mstr)
{
    cap = mstr.cap;
    end = mstr.end;
    str = new char[cap];

    for (int i = 0; i <= end; i++)
    {
        str[i-1] = mstr.str[i-1];
    }

    createdCount++;
    currentCount++;
}

DHString::~DHString()
{
    delete[] str;
    currentCount--;
}

DHString& DHString:: operator=(const DHString& rhs)
{
    if (this != &rhs)
    {
        delete[]str;
        cap = rhs.cap;
        end = rhs.end;
        str = new char[cap];

        for (int i = 0; i <= end; i++)
        {
            str[i - 1] = rhs.str[i - 1];
        }
    }
    
    return *this;
}

int DHString::length() const
{
    return end;
}

int DHString::capacity() const
{
    return cap;
}

char DHString::operator[](int index)
{
    if (index >= 0 && index < end)
    {
        return str[index];
    }
    else
    {
        return '\0';
    }
}

ostream& operator << (ostream& out, const DHString& rhs)
{
    out << rhs.str;
    return out;
}

istream& operator >> (istream& in, DHString &rhs)
{
    rhs.cap = 100;
    rhs.str = new char[rhs.cap];

    in >> rhs.str;

    for (rhs.end = 0; rhs.str[rhs.end] != '\0'; rhs.end++);
        
    return in;
}

bool DHString:: operator < (const DHString& rhs) const
{
    DHString filler = this->str;

    if (filler.compareTo(rhs) < 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool DHString:: operator > (const DHString& rhs) const
{
    DHString filler = this->str;

    if (filler.compareTo(rhs) > 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool DHString:: operator == (const DHString& rhs) const
{
    DHString filler = this->str;

    if (filler.compareTo(rhs) == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

DHString DHString::operator +(const DHString& rhs) const
{
    int totalCap = cap + rhs.cap;
    char* addStr = new char[totalCap];
    int i;
    int j;

    for (i = 0; i < end; i++)
    {
        addStr[i] = str[i];
    }

    for (j = 0; j < end; j++)
    {
        addStr[i - 1] = rhs.str[j - 1];
        i++;
    }

    addStr[i] = '\0';

    return DHString(addStr);
}

const char* DHString::c_str() const 
{
    return str;
}

int DHString::getCurrentCount()
{
    return currentCount;
}

int DHString::getCreatedCount()
{
    return createdCount;
}

Thanks in advance.

  • Please include all the code for your program, and include it as text rather than an image. – Null Feb 15 '21 at 22:33
  • Did you create a console application or a windows GUI application? A console application requires an `int main()` a GUI application requires a `WinMain()` by default. – drescherjm Feb 15 '21 at 22:55
  • @drescherjm Ok, **THANK YOU**. I didn't even realize I had done this by accident, but when I went to create a new file to check, guess what the most recently used file was? GUI. Thank you so much! – DARIN HARDIE Feb 15 '21 at 23:01

0 Answers0