|
The following program always says "local function definition is illegal", but I can't find the error. I haven't implemented the function in the class definition. What are the general situations of "local function definition illegal"? I have also seen a situation where the function definition is written in the class, and errors will appear outside. What is going on? can everyone give some advice,
//This file is used for StuInfoManager class definition
#ifndef H_STUINFOMANAGER
#define H_STUINFOMANAGER
#include"StuInfoVec.h"
//StuInfoManager class definition
#endif
class StuInfoManager:public StuInfoVec
{
protected:
bool isModified;//Whether the student information has been modified and has not been saved
int toRemvNodes;//The number of records marked for deletion
public:
static char* subject[];
protected:
//Menu selection function
char menuSelect();
//Display header
void dispTable();
//Display a record of information
void dispRecord(Record *rec);
//Find out the ranking of a given total score in all records
int getIndex(float sum);
public:
StuInfoManager();
virtual ~StuInfoManager()
{}
//Start the user interface operation of the score management program
virtual void start();
//Menu processing function
virtual void handleMenu();
//Display record
virtual void displayRecords();
//Search record
virtual void queryRecord();
//Add record
virtual void addRecord();
//Delete Record
virtual void removeRecord();
//Mark delete record
virtual void removeNote(bool isToRemove);
//Modify record
virtual void modifyRecord();
//Record sort
virtual void sortRecords();
//Save the record
virtual void saveRecords();
//Read record
virtual void loadRecords();
//End the program
virtual void quit();
//Clear the current record
virtual void clear();
};
//////////////////
/This file is used for StuInfoManager class implementation and main function implementation
#include<fstream>
#include "StuInfoManager.h"
using namespace std;
//Delete Record
void StuInfoManager::removeRecord()
{
if(empty())
{
cout<<"The record is empty, exit the delete operation!"<<endl;
return;
}
cout<<"1 Mark the record to be deleted\n"<<"2 Execute the mark\n"<<"3 Cancel the delete mark of the specified record\n"<<"4 Cancel all delete records"<<endl;
string str;
do
{
cout<<"Please select the operation (1~4):";
cin>>str;
}while(str[0]<'1'||str[0]>'4');
switch(str[0])
{
case '1':
//This write, mark the record to be deleted
removeNote(true);
break;
case '2':///execution flag
{
int num=removePerform();
toRemvNodes=0;
cout<<"Deleted a total of "<<num<<"\n"<<"Now there are still "<<size()<<"records"<<endl;
if(num!=0) isModified=true;
}
break;
case '3':
//Cancel the delete mark of the specified record
removeNote(true);
break;
case '4'://cancel all delete records
{
iter it;
iter it_end=last();
for(it=first();it!=it_end;it++)
(*it)->toBeDeleted=false;
toRemvNodes=0;
cout<<"All deletion marks have been cancelled"<<endl;
}
}
}
//Mark delete record
void StuInfoManager::removeNote(bool isToRemove)//--------------------------------------- OK
{
if(empty())
{
cout<<"Currently there is no record"<<endl;
return;
}
if(!isToRemove&&toRemvNodes==0)
{
cout<<"There are currently no items marked for deletion"<<endl;
return;
}
char choice;
char pattern[20];
int type;
while(true)
{
cout<<"Please enter the recording method of the change mark:\n"\
<<"1. According to the student number\n"<<"2. According to the name\n"<<"3. According to the order\n"\
<<"4. End the removal operation\n";
cin>>choice;
if(choice=='4') break;
if(choice=='1')
{cout<<"Please enter the student ID you want to inquire:";
type=0;
}else if(choice=='2')
{cout<<"Please enter the name of the student you want to query:";
type=1;
}else{ cout<<"Please enter the rank of the student you want to inquire:";
type=2;
}
cin>>pattern;
bool getMatch=false;
iter it=findRecord(pattern,type,first());
iter it_end=last();
while(it!=it_end)
{
//To cancel the mark and the current record is not marked, or to mark but the current record is already marked, continue to the next record
if((!isToRemove&&!(*it)->toBeDeleted)||(isToRemove&&(*it)->toBeDeleted))
{it=findRecord(pattern,type,++it); continue;}
getMatch=true;
cout<<"A matching record was found:\n";
dispTable();
dispRecord(*it);
cout<<"Are you sure you want to change the mark of this record? [y/n]";
cin>>choice;
//Change the mark of this record
if(choice!='n'&&choice!='N')
(*it)->toBeDeleted=! (*it)->toBeDeleted;
if(isToRemove)
toRemvNodes++;
else toRemvNodes--;
it=findRecord(pattern,type,++it); //Take down a matching record
}
if(!getMatch)
cout<<"No matching records were found"<<endl;
else
{if(toRemvNodes!=0)
cout<<"Currently there are "<<toRemvNodes<<" records have been marked for deletion"<<endl;
else cout<<"Now there are no records marked for deletion\n";
}
}
}
//Modify record
void StuInfoManager::modifyRecord()
{//Similar to some functions on removeNote, select the operation method is to select by student number, name, rank or end
if(empty())
{
cout<<"Currently there is no record"<<endl;
return;
}
char choice;
char pattern[20];
int type;
while(true)
{
cout<<"Please enter how to find the way to modify the record:\n"\
<<"1. According to the student number\n"<<"2. According to the name\n"<<"3. According to the order\n"\
<<"4. End query\n";
cin>>choice;
if(choice=='4') break;
if(choice=='1')
{cout<<"Please enter the student ID you want to inquire:";
type=0;
}else if(choice=='2')
{cout<<"Please enter the name of the student you want to query:";
type=1;
}else{ cout<<"Please enter the rank of the student you want to inquire:";
type=2;
}
cin>>pattern;
bool getMatch=false;
iter it=findRecord(pattern,type,first());
iter it_end=last();
while(it!=it_end)
{
getMatch=true;
cout<<"A matching record was found:\n";
dispTable();
dispRecord(*it);
cout<<"Are you sure you want to change this record? [y/n]";
cin>>choice;
//Change the mark of this record
if(choice!='n'&&choice!='N')
break;
if(choice!='y'&&choice!='Y')
{
cout<<"Please re-enter student information:"<<endl;
cout<<"Please enter student ID:";
cin>>(*it)->number;
//The operation is similar, enter the name, gender, and grades of each subject
cout<<" Please enter your name:";
cin>>rec->name;
cout<<"Please enter the gender (0 means female, 1 means male):";
for(i=0;i<NUM_SUBJECT;i++)
{
cout<<"Please enter the result of "<<subject[i]<<":";
cin>>rec->score[i];
sum+=rec->score[i];
}
rec->sum=sum;
rec->average=sum/NUM_SUBJECT;
rec->index=getIndex(sum);
StuInfoVec::addRecord(rec);
}
}
int ncount=0;
iter it1;
for(it1=first(); it1!=it_end; it1++)
{
if(it1==it) continue;
if((*it1)->index>tmpi&&(*it1)->sum>=sum)
(*it1)->index--;
else if((*it1)->index<=tmpi&&(*it1)->sum<sum)
(*it1)->index++;
if((*it1)->sum>sum)
ncount++;
}
//ncount is the number of students whose total score is greater than the total score of the current student
//The current student's ranking is ncount+1
(*it)->index=ncount+1;
isModified=true;
//Take down a matching record
it=findRecord(pattern,type,++it);
}
cout<<"finished all records\n"<<endl;
}
////////////////////////
studentManagement\StuInfoManager.cpp(215): error C2601:'removeRecord': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(259): error C2601:'removeNote': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(323): error C2601:'modifyRecord': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(411): error C2601:'sortRecords': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(416): error C2601:'saveRecords': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(423): error C2601:'loadRecords': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(428): error C2601:'quit': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(436): error C2601:'clear': local function definitions are illegal
E:\C++exercise\studentManagement\StuInfoManager.cpp(463): error C2601:'main': local function definitions are illegal
E:\C++ exercise\studentManagement\StuInfoManager.cpp(473): fatal error C1004: unexpected end of file found
Error executing cl.exe.
StuInfoManager.obj-10 error(s), 0 warning(s)
Really dizzy |
|