Search code examples
c++classoopforward-declaration

My C++ code is not working (for class declaration)


I am having problem in this code. I have modified it a lot, but always the compiler shows an error of "Too many types in declaration", "Declaration ended incorrectly" and "Multiple declaration". Please help me. Note: This is just the beginning of the code. I could not post the full code because of the limitations. If you want, I will send it to you...

#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


Solution

  • Follow your class and struct declarations with a semicolon. It's there for declarations of variables of that type, and typedefs.