Solved

Destructor error

Posted on 2004-04-21
5
456 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TTimer no longer functioning 7 91
SNMP error No Such Object available on this agent at this OID 3 252
Unresolved External Symbols 3 84
Create a path if not exists 7 77
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 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