| |

VerySource

 Forgot password?
 Register
Search
View: 1344|Reply: 10

Why always say "local function definition is illegal"

[Copy link]

2

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-11 10:00:01
| Show all posts |Read mode
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
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-11 12:30:01
| Show all posts
Since it is an exercise, why not package the source code and upload it.
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-11 13:00:01
| Show all posts
From the last error, it may be that the cpp file does not contain stdafx.h.
Reply

Use magic Report

2

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-11-11 13:30:01
| Show all posts
It’s not an exercise, it’s the course design we’re going to do, just put it in that folder. There is no stdafx.h. A console program, the functions inside can be said to be no problem, except that it has not been defined, but the display shows that both the defined and the undefined are regarded as illegal definitions
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-11 13:45:01
| Show all posts
The VC project you built requires stdafx.h, if there is no VC, an error will be reported.
You can create a new project that does not require stdafx.h. It might be right.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-11-11 14:00:01
| Show all posts
studentManagement\StuInfoManager.cpp(215): error C2601:'removeRecord': local function definitions are illegal
Very simple error message.
This means that the {} mismatches in the function definitions between the removeRecord function, {more than }, so that the compiler thinks that the previous function has not ended, then you define the new function removeRecord inside the previous function, which is local Function definition is not allowed in C/C++.
Reply

Use magic Report

2

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-11-11 14:30:01
| Show all posts
Look again
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-11-11 15:15:01
| Show all posts
The error message should be that "{" is not the same as "}", but I count the same number again -_-b

But this
#ifndef H_STUINFOMANAGER
#define H_STUINFOMANAGER
#include"StuInfoVec.h"
//StuInfoManager class definition
#endif
The #endif inside should be put at the end of .h, right?
Reply

Use magic Report

2

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-11-11 15:45:01
| Show all posts
I found it. The {} number of the previous function is inconsistent
Thank you all
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-11 17:00:01
| Show all posts
3q very much!!!!! That is, the last function curly braces do not match! ! ! ! I also encountered the same problem! !
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list