Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Destructor error

Posted on 2004-04-21
5
457 Views
Last Modified: 2008-03-17
I created the following program in VC++ 6.0.
Without the destructor everything compiles and runs fine.

This is my compilation error with the Destructor:

compiling...
Prog6-2167.cpp
c:\2613\p06\prog6-2167.cpp(276) : fatal error C1001: INTERNAL COMPILER ERROR
        (compiler file 'msc1.cpp', line 1794)
         Please choose the Technical Support command on the Visual C++
         Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

Prog6-2167.exe - 1 error(s), 0 warning(s)



Heres is my somewhat lengthy code
The destructor is defined at the bottom:


#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<new>


using namespace std;

struct Node

      {

             string word;        // the word  

             int wordCount;      // times the words has occurred

             Node *nextPtr;      // points to the next node

      };



class List
{
private:
      Node *head;   //List head pointer
      Node * createNode(string);
public:
   
      List()   {head=NULL;};
      ~List();   //Destructor  
    void loadNode(string str);
    void findMax();
};


bool openfile(ifstream &, char [20]);
void DisplayFile();

int main()
{

      DisplayFile();
      List list;

      ifstream ifile;

if (!openfile(ifile,"inputfile.txt"))
{
      cout<<"Error opening inputfile.txt "<<endl;
      exit(1);
}
     
   

  string line;
 
int word_size=0;
int word_count=0;
  while(ifile>>line)
  {
        
        for(int i=0;i<line.size();i++)
        {
              if(toupper(line[i])==tolower(line[i]))  //omits punctuation
              {
                    line.erase(i,1);
                 
              }
         
        }
  word_count++;
  word_size+=line.size();
   list.loadNode(line);
   
  }
  list.findMax();
  cout<<"The total number of words: "<<word_count<<endl;
  cout<<"Average word size: "<<word_size/word_count<<endl;
 
 
 

return 0;
}

//---------------------------------------------------------
//Function createNode uses the new operator to
//create a Node. It then returns the Node to be added
//to the list.
//----------------------------------------------------------
  Node * List::createNode(string ptr)
{
      Node *newNode;
      newNode=new Node;
      newNode->word=ptr;
      newNode->wordCount=1;
      newNode->nextPtr=NULL;
      return newNode;
}

//-----------------------------------------------------
//Function openfile opens the input file
//-----------------------------------------------------

  bool openfile(ifstream &file, char filename[20])
{
      bool status;
      file.open(filename);
      if (file.fail())
            status=false;
      else
            status=true;
      return status;
}


//---------------------------------------------------------------------------
//Function loadNode takes a string form the input file and creates a Node in
//the linked list. It first determines if the list is empty then it determines
//if the string exists within the list.
//----------------------------------------------------------------------------
void List::loadNode(string str)
{
      Node *newNode,*nodePtr, *previousNode;
      
            newNode=createNode(str);
          
      

      //If there are no nodes in the list or new node is smaller
      //than the first node then
      //make the new node the first node
      if (!head||(strcmpi(str.c_str(),head->word.c_str())<0))
      {                
            
            newNode->nextPtr=head;
          head=newNode;
      }
      
      
            //otherwise, insert the new node
            //at the correct place in the list
      
      else
      {
            //Initiliaze nodePtr to head of the list
            nodePtr= head;
            
      
            while(nodePtr) //&&(!strcmpi(nodePtr->word.c_str(),str.c_str())<0))
            {  
                  
                  if(strcmpi(nodePtr->word.c_str(),str.c_str())==0)
                  {
                        
                  nodePtr->wordCount++;
                  return;
                  }
              else
                  {  
                     previousNode=nodePtr;
               nodePtr=nodePtr->nextPtr;
                  }
            }
              //Insert the new Node as the last node
      previousNode->nextPtr=newNode;
      newNode->nextPtr=nodePtr;
      }
   

   
}
//---------------------------------------------------------------------------
//Function DisplayFile displays each character of the input file
//---------------------------------------------------------------------------
void DisplayFile()
{
            ifstream ifile;

if (!openfile(ifile,"inputfile.txt"))
{
      cout<<"Error opening inputfile.txt "<<endl;
      exit(1);
}
      
      
      char ch;
       while( ifile.get(ch) )
      {
          cout << ch;
      
   }
       cout<<endl;
      ifile.close();
      cout<<endl;
}

//----------------------------------------------------------------------------
//Function findMax searches for the highest value of wordCount
//it then dispays the corresponding words of max occurances.
//----------------------------------------------------------------------------


void List::findMax()
{



Node *nodePtr;
nodePtr=head;
int max=1;
while(nodePtr)       //searches for highest value of wordCount
      
      {
            if(max>=nodePtr->wordCount)
            {
                  
               
            nodePtr=nodePtr->nextPtr;
            }
      else
      {
            max=nodePtr->wordCount;
         nodePtr=nodePtr->nextPtr;
      }
      }

nodePtr=head; //reset nodePtr to head


cout<<"The most used words occuring "<<max<<" times are:"<<endl;

while(nodePtr)    //Find all values equal to max
{
   if (nodePtr->wordCount==max)
   {
         cout<<nodePtr->word<<"    ";

   }

   nodePtr=nodePtr->nextPtr;

}

cout<<endl;
cout<<endl;


}

//-----------------------------------
//Destructor deletes nodes
//-----------------------------------
List::~List
{
      Node *nodePtr, *nextNode;

nodePtr=head;
while(nodePtr!=NULL)
{
      nextNode=nodePtr->next;
      delete nodePtr;
      nodePtr=nextNode;

}

0
Comment
Question by:Stella Pauley
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 10882042
This is a commpn indication that you have

a) not the latest service pack
b) not enough comment lines in your code (and yes, I am serious)

Regarding a)

Get either

http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/default.aspx (SP5, well tested)

or

http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp6/default.aspx (SP6, quite new)

Regarding b)

These "internal compiler errors" are hard to tackle, but seriously, inserting or removing lines before the line that caused that problems helps in some cases :o)

0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10882310
I have service pack 6 installed...

0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 10882381
Then, try to "Rebuild all". Oh, and make the destructor read

List::~List() // <---- the brackets were missing :-(
{
    Node *nodePtr, *nextNode;

nodePtr=head;
while(nodePtr!=NULL)
{
    nextNode=nodePtr->next;
    delete nodePtr;
    nodePtr=nextNode;

}
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10882416
You hit it on the mark.
I had forgot the parameter parathensis ( ) at the end of the Destructor in the definition.


0
 
LVL 86

Expert Comment

by:jkr
ID: 10882435
>>You hit it on the mark.

Should have seen that *way* earlier :-(
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 160
object oriented programming comparison 5 77
c++, dynamic object by json 1 53
Adding items to a C# list incrementally 5 28
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question