2 Replies - 754 Views - Last Post: 16 February 2011 - 09:20 AM Rate Topic: -----

#1 strife13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 24-February 08

Link error

Posted 16 February 2011 - 09:06 AM

This is the error I received 1>LINK : fatal error LNK1561: entry point must be defined but can not find anything on line that would help me to correct the error. As always any help would be appreciated.

#include <iostream>
#include <string>
#include <cstddef>     // for NULL
#include <new>         // for bad_alloc
#include <tchar.h>
#include "ListP.h"     // header file

int countValue(List front ,const int item);

using namespace std;

// definitions of methods follow:
//   . . .

List::List(const List& aList)
   : size(aList.size)
{
   if (aList.head == NULL)
      head = NULL;  // original list is empty

   else
   {  // copy first node
      head = new ListNode;
      head->item = aList.head->item;

      // copy rest of list
      ListNode *newPtr = head;  // new list pointer
      // newPtr points to last node in new list
      // origPtr points to nodes in original list
      for (ListNode *origPtr = aList.head->next;
       origPtr != NULL;
       origPtr = origPtr->next)
      {  newPtr->next = new ListNode;
         newPtr = newPtr->next;
     newPtr->item = origPtr->item;
      }  // end for

      newPtr->next = NULL;
   }  // end if
}  // end copy constructor

List::~List()
{
   while (!isEmpty())
      remove(1);
}  // end destructor

bool List::isEmpty() const
{
   return size == 0;
}  // end isEmpty

int List::getLength() const
{
   return size;
}  // end getLength

List::ListNode *List::find(int index) const
{
   if ( (index < 1) || (index > getLength()) )
      return NULL;

   else  // count from the beginning of the list.
   {  ListNode *cur = head;
      for (int skip = 1; skip < index; ++skip)
         cur = cur->next;
      return cur;
   }  // end if
}  // end find

void List::retrieve(int index,
                    ListItemType& dataItem) const
   throw(ListIndexOutOfRangeException)
{
   if ( (index < 1) || (index > getLength()) )
      throw ListIndexOutOfRangeException(
     "ListIndexOutOfRangeException: retrieve index out of range");
   else
   {  // get pointer to node, then data in node
      ListNode *cur = find(index);
      dataItem = cur->item;
   }  // end if
}  // end retrieve

void List::insert(int index, const ListItemType& newItem)
   throw(ListIndexOutOfRangeException, ListException)
{
   int newLength = getLength() + 1;

   if ( (index < 1) || (index > newLength) )
      throw ListIndexOutOfRangeException(
     "ListIndexOutOfRangeException: insert index out of range");
   else
   {  // try to create new node and place newItem in it
      try
      {
     ListNode *newPtr = new ListNode;
     size = newLength;
     newPtr->item = newItem;

     // attach new node to list
     if (index == 1)
     {  // insert new node at beginning of list
        newPtr->next = head;
        head = newPtr;
     }
     else
     {  ListNode *prev = find(index-1);
            // insert new node after node
            // to which prev points
            newPtr->next = prev->next;
        prev->next = newPtr;
     }  // end if
      }  // end try
      catch (bad_alloc e)
      {
     throw ListException(
        "ListException: memory allocation failed on insert");
      }  // end catch
   }  // end if
}  // end insert

void List::remove(int index) throw(ListIndexOutOfRangeException)
{
   ListNode *cur;

   if ( (index < 1) || (index > getLength()) )
      throw ListIndexOutOfRangeException(
     "ListIndexOutOfRangeException: remove index out of range");
   else
   {  --size;
      if (index == 1)
      {  // delete the first node from the list
         cur = head;  // save pointer to node
         head = head->next;
      }

      else
      {  ListNode *prev = find(index - 1);
         // delete the node after the node to which prev points
         cur = prev->next;  // save pointer to node
     prev->next = cur->next;
      }  // end if

      // return node to system
      cur->next = NULL;
      delete cur;
      cur = NULL;
   }  // end if
   //start of portion provided for this assignment
   int _tmain(int argc, _TCHAR* argv[]);
   {
List front;
int listCount;
cout << "Enter the size of the list: ";
cin >> listCount;
for (int i = 1; i <= listCount; i++)
front.insert(i,rand()%5);
cout << "Original List of Values:    "  << endl;
//writeLinkedList(front, "  ");
cout << endl;
for(int j=0;j<5;++j)
cout << countValue (front,j) << endl;
cout << endl;
//return 0; removed because it returned a value
}//end portion of program provided for this assignment

 //counts the number of times each number appears in the random sequence
ListNode* countValue(ListNode *pHead);

{
      int count0;
      int count1;
      int count2;
      int count3;
      int count4;
      ListNode *pNode;
      for(pNode->next != NULL; pNode = pNode->next;)
    
      {
          if(pNode->item == 0)   

          {  count0++;}    
          if(pNode->item == 1)

          { count1++;}

          if(pNode->item == 2)

          {count2++;}

          if(pNode->item == 3)  

          {count3++;}  

          if(pNode->item == 4)

          {count4++;}
              
      }
      cout << "0: " << count0 << endl; //displays the prior count
      cout << "1: " << count1 << endl;
      cout << "2: " << count2 << endl;
      cout << "3: " << count3 << endl;
      cout << "4: " << count4 << endl;     
}
getchar(); //pause program to confirm output

} 


Is This A Good Question/Topic? 0
  • +

Replies To: Link error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6032
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: Link error

Posted 16 February 2011 - 09:09 AM

You might try removing the ; in this line:
int _tmain(int argc, _TCHAR* argv[]);

Was This Post Helpful? 0
  • +
  • -

#3 strife13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 24-February 08

Re: Link error

Posted 16 February 2011 - 09:20 AM

Embarrassing :sweatdrop:

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1