我的 C++ 代码不工作(对于 class 声明)
My C++ code is not working (for class declaration)
我在这段代码中遇到问题。
我修改了很多,但编译器总是显示"Too many types in declaration"、"Declaration ended incorrectly"和"Multiple declaration"的错误。
请帮我。
注意:这只是代码的开头。由于限制,我无法 post 完整代码。
要的话我发给你...
#include <conio.h>
#include <iomanip.h>
#include <string.h>
#include <iostream.h>
#define HR for(j=0;j<80;j++) cout<<"-";
#define SR for(j=0;j<80;j++) cout<<"=";
#define NEWLINE cout<<"\n";
class stud {friend class getrec;friend class sortrec;friend class list;friend class search;friend class edit;friend class delrec;}
class getrec{public:void f(class stud);};
class sortrec{public:void f(class stud);};
class list{public:void f(class stud);};
class search{public:void f(class stud);};
class edit{public:void f(class stud);};
class delrec{public:void f(class stud);};
struct student
{
char name[20],sub[10];
long roll,code;
int internal,external;
}
class stud
{
friend class getrec;
friend class sortrec;
friend class list;
friend class search;
friend class edit;
friend class delrec;
private:
int choice,i,j,c,cur,b,rec;
//char name[20];
struct student e[96],t;
public:
stud()
{
for (c=0;c<96;c++)
{
e[i].internal=0;
e[i].external=0;
e[i].roll=-1;
e[i].code=0;
strcpy(e[i].name,"");
strcpy(e[i].sub,"");
}
}
int menu(void)
{
clrscr();
cout<<"\tThe Database Management System of Employees"<<endl;
cout<<"Choose any of these options by pressing any of their corresponding numbers"<<endl;
cout<<"1. List he records."<<endl;
cout<<"2. Delete old record."<<endl;
cout<<"3. Insert new record."<<endl;
cout<<"4. Edit record."<<endl;
cout<<"5. Search for a record."<<endl;
cout<<"6. Sort entries."<<endl;
cout<<"7. Quit."<<endl;
choice=getch();
return choice;
}
~stud()
{
clrscr();
cout<<"The Database has been deleted.";
getch();
}
void program(void)
{
do
{
menu();
switch (choice)
{
case '1':
list();
break;
case '2':
delrec();
break;
case '3':
getrec();
break;
case '4':
edit();
break;
case '5':
search();
break;
case '6':
sortrec();
break;
}
} while (choice!='7');
}
void getrec(class getrec g)
{
g.f();
}
void sortrec(class sortrec s)
{
s.f();
}
void list(class list l)
{
l.f();
}
void search(class search s)
{
s.f();
}
void edit(class edit e)
{
e.f();
}
void delrec(class delrec d)
{
d.f();
}
}
Error image
在您的 class 和结构声明后加上分号。它用于声明该类型的变量和类型定义。
我在这段代码中遇到问题。 我修改了很多,但编译器总是显示"Too many types in declaration"、"Declaration ended incorrectly"和"Multiple declaration"的错误。 请帮我。 注意:这只是代码的开头。由于限制,我无法 post 完整代码。 要的话我发给你...
#include <conio.h>
#include <iomanip.h>
#include <string.h>
#include <iostream.h>
#define HR for(j=0;j<80;j++) cout<<"-";
#define SR for(j=0;j<80;j++) cout<<"=";
#define NEWLINE cout<<"\n";
class stud {friend class getrec;friend class sortrec;friend class list;friend class search;friend class edit;friend class delrec;}
class getrec{public:void f(class stud);};
class sortrec{public:void f(class stud);};
class list{public:void f(class stud);};
class search{public:void f(class stud);};
class edit{public:void f(class stud);};
class delrec{public:void f(class stud);};
struct student
{
char name[20],sub[10];
long roll,code;
int internal,external;
}
class stud
{
friend class getrec;
friend class sortrec;
friend class list;
friend class search;
friend class edit;
friend class delrec;
private:
int choice,i,j,c,cur,b,rec;
//char name[20];
struct student e[96],t;
public:
stud()
{
for (c=0;c<96;c++)
{
e[i].internal=0;
e[i].external=0;
e[i].roll=-1;
e[i].code=0;
strcpy(e[i].name,"");
strcpy(e[i].sub,"");
}
}
int menu(void)
{
clrscr();
cout<<"\tThe Database Management System of Employees"<<endl;
cout<<"Choose any of these options by pressing any of their corresponding numbers"<<endl;
cout<<"1. List he records."<<endl;
cout<<"2. Delete old record."<<endl;
cout<<"3. Insert new record."<<endl;
cout<<"4. Edit record."<<endl;
cout<<"5. Search for a record."<<endl;
cout<<"6. Sort entries."<<endl;
cout<<"7. Quit."<<endl;
choice=getch();
return choice;
}
~stud()
{
clrscr();
cout<<"The Database has been deleted.";
getch();
}
void program(void)
{
do
{
menu();
switch (choice)
{
case '1':
list();
break;
case '2':
delrec();
break;
case '3':
getrec();
break;
case '4':
edit();
break;
case '5':
search();
break;
case '6':
sortrec();
break;
}
} while (choice!='7');
}
void getrec(class getrec g)
{
g.f();
}
void sortrec(class sortrec s)
{
s.f();
}
void list(class list l)
{
l.f();
}
void search(class search s)
{
s.f();
}
void edit(class edit e)
{
e.f();
}
void delrec(class delrec d)
{
d.f();
}
}
Error image
在您的 class 和结构声明后加上分号。它用于声明该类型的变量和类型定义。