-
fatal error C1001
I am getting an error:
cpp1.cpp(18) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1794)
I think this may have something to do with my header files, but they are included correctly.
Code:
#include <iostream.h>
#include <fstream.h>
#include <ctype.h>
#include <iomanip.h>
#include "student.h"
#include "StudentLinkList.h"
//Main function
int main(void) //This is line 18
{
char cmd;
do{
cout << "Please enter a command: R)ead, L)ist, G)rades, A)dd, D)elete, S)ave, or Q)uit" << endl;
cin >> cmd;
switch ( cmd = toupper(cmd))
{
case 'R':
s.ReadFile ();
break;
case 'L':
s.List ();
break;
case 'G':
s.Grades ();
break;
case 'A':
s.Add ();
break;
case 'D':
s.Delete ();
break;
case 'Q':
break;
case 'S':
s.Save ();
break;
default:
cout << "Invalid Command. ";
}
}while(cmd!='Q');
return 0;
}
-
VC++6 is useless...
Nothing remarkable here, it's probably something in the headers.
But you're using the outdated C++ headers.
-
There are usually workarounds...
Let's see your student.h and StudentLinkList.h.
And avoid using globals, "s", unless you really need them.
gg
-
Student.h file
Code:
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream.h>
#include "str.h"
class Student{
Str name;
int grade;
public:
Student(char *n="", int g=0);
friend istream &operator >> (istream &in, Student &student);
friend ostream &operator << (ostream &out, Student &student);
friend class StudentList;
};
class StudentList{
Student *p;
int count;
public:
StudentList (int n=20);
~StudentList();
void ReadFile();
void Sortbyname();
void Sortbygrade();
void List();
void Grades();
void Add();
void Delete();
void Save();
};
#endif
StudentLinkList.h file
Code:
#ifndef STUDENTLINKLIST_H
#define STUDENTLINKLIST_H
#include "student.h"
#include <iostream.h>
#include <fstream.h>
typedef class StudentNode * PStudentNode;
class StudentNode{
Student s;
PStudentNode next;
public:
StudentNode (char *p="", int grade=0);
friend istream & operator >> (istream&, StudentNode&);
friend ostream & operator << (ostream&, StudentNode&);
friend class StudentLinkList;
};
class StudentLinkList{
PStudentNode top;
public:
StudentLinkList();
~StudentLinkList();
void ReadFile();
void List();
void Insert (PStudentNode);
void Delete ();
void Sortbygrade ();
void Grades();
void Save ();
};
#endif;
-
Now str.h - and anything else I need to compile (code wise).
gg
-
str.h file:
Code:
#ifndef STR_H
#define STR_H
#include <iostream.h>
#include <string.h>
class Str { //create class 'str'
char s[32]; //define array of 32 characters
public:
Str (char *p=""); //ctor (default)
int operator<(Str &str); //operator
int operator==(Str &str);
friend istream & operator>>(istream &in, Str &str);
friend ostream & operator<<(ostream &out, Str &str);
};
#endif
StudentLinkList.cpp:
Code:
#include "StudentLinkList.h"
#include <iomanip.h>
#include <iostream.h>
#include <fstream.h>
#include <ctype.h>
#include <iomanip.h>
StudentNode::StudentNode (char *p, int grade) :s(p,grade) { next=NULL;}
istream &operator >> (istream &in, StudentNode &s){
in >> s.s;
return in;
}
StudentLinkList::StudentLinkList(){
top=NULL;
}
StudentLinkList::~StudentLinkList(){
while (top!=NULL)
{
PStudentNode p=top;
top=top -> next;
delete p;
}
}
void StudentLinkList::List(){
PStudentNode curr=top;
while (curr!=NULL)
{
cout << curr->s << endl;
curr = curr->next;
}
}
void StudentLinkList::ReadFile(){
ifstream infile;
char fn[64];
cout <<"Enter the file name:";
infile.open (fn,ios::nocreate);
if (infile)
{
while (!infile.eof())
{
PStudentNode p=new StudentNode;
infile >> *p;
Insert (p);
}
infile.close();
}
}
void StudentLinkList::Insert (PStudentNode NewNode){
if (top==NULL) top=NewNode;
else if (NewNode->s.Name() < top->s.Name() )
{
NewNode ->next = top;
top = NewNode;
}
else
{
PStudentNode curr = top, prev;
while (curr !=NULL && curr->Name() < NewNode->s.Name() )
{
prev = curr;
curr = curr->next;
}
prev->next = NewNode;
NewNode -> next = curr;
}
}
void StudentLinkList::Delete (str name){
{
if (top->Name==name)
{
PStudentNode tmp=top;
top = top->next;
delete tmp;
}
else
{
PStudentNode curr=top,prev;
while(curr!=NULL && curr->name != name)
{
prev=curr;
curr=curr -> next;
}
if(curr !=NULL)
{
prev->next = curr->next;
delete curr;
}
}
}
}
-
First thing I get is:
>> error C2065: 's' : undeclared identifier
So atleast you're not using globals :)
The first thing you need to do is make sure your compiler is up-to-date with any patches or service packs. If you are running VC++ 6.0 (as it seems) them you should apply service pack 6 for that product:
http://msdn.microsoft.com/vstudio/do...6/default.aspx
Once the compiler stops blowing up, you should be on your way to resolving issues in your code. Although now that your code is here for the world see, you might get some constructive criticism while you're waiting for SP6 to download :)
gg
-
I don't see how that's possible. I do have SP6, and just for giggles I reinstalled it. I am getting the same error.
-
>> int main(void) //This is line 18
That's line 10 for me - have you shown all your code?
Zip up your project and source files (*.dsp, *.dsw, *.cpp, *.h) and attach it to the thread.
gg
-
I had just removed some commented lines required by my instructor.
I will attach the files.
-
-
just for kicks and something quick and easy to try:
make this:
int main(void)
this:
int main()
and add this:
StudentLinkList s;
in main before the switch statement somewhere.
Also, I suggest you stop using s as the variable name for everything. The more s's you have as variables, the harder it is to keep which scope each s has.
-
Still no blow-up. Here's what I would try:
- uninstall Visual Studio
- hit windows update and get the OS up-to-date
- re-install Visual Studio
- re-apply SP6
In the mean time:
Code:
Compiling...
StudentLinkList.cpp
studentlinklist.cpp(56) : error C2039: 'Name' : is not a member of 'Student'
student.h(11) : see declaration of 'Student'
studentlinklist.cpp(56) : error C2039: 'Name' : is not a member of 'Student'
student.h(11) : see declaration of 'Student'
studentlinklist.cpp(64) : error C2039: 'Name' : is not a member of 'StudentNode'
studentlinklist.h(8) : see declaration of 'StudentNode'
studentlinklist.cpp(64) : error C2039: 'Name' : is not a member of 'Student'
student.h(11) : see declaration of 'Student'
studentlinklist.cpp(64) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
StudentLinkList.obj - 5 error(s), 0 warning(s)
Code:
Compiling...
Cpp1.cpp
cpp1.cpp(27) : error C2065: 's' : undeclared identifier
cpp1.cpp(27) : error C2228: left of '.ReadFile' must have class/struct/union type
cpp1.cpp(30) : error C2228: left of '.List' must have class/struct/union type
cpp1.cpp(33) : error C2228: left of '.Grades' must have class/struct/union type
cpp1.cpp(36) : error C2228: left of '.Add' must have class/struct/union type
cpp1.cpp(39) : error C2228: left of '.Delete' must have class/struct/union type
cpp1.cpp(44) : error C2228: left of '.Save' must have class/struct/union type
Error executing cl.exe.
Cpp1.obj - 7 error(s), 0 warning(s)
gg
-
Hmm, well thank you for your help on this. I honestly don't know why I am getting this error.. Windows XP SP2, perhaps?
-
If so, it wouldn't be the first problem with SP2 that I've heard of :)
gg
-
Getting back to CornedBee's comment on outdated headers, here's some reading on the subject:
iosteam vs iostream.h
FAQ: C++ Namespaces
gg