hello,in my main program i can see 3 mistakes in .h file:
#ifndef AC_H
#define AC_H
class Student;
class Address;
class Group;
class Depart;
class Student
/*(11)*/{
private:
int sid;
char sname[80];
//class Address address;
public:
void setSid(int sid);
void setSname(char *s);
int getSid();
void getSname(char *sname);
};
class Address
{
class Student* st;
private:
char coun[30]; //country
char city[30]; //city
char strt[30]; //street
int hsno; //house number
int phno; //phone number;
//class Group group;
public:
Address(Student* s);
void setCoun(char coun);
void setCity(char city);
void setStrt(char strt);
void setHsno(int hsno);
void setPhno(int phno);
void getCoun(char *coun);
void getCity(char *city);
void getStrt(char *strt);
int getHsno();
int getPhno();
};
class Group
/*(49)*/{
class Address* ad;
private:
char gname[20]; //group name
Student stud[30]; //using Student information
//class Depart depart;
public:
Group(Address* a);
void setGname(char gname);
void getGname(char *gname);
};
class Depart
/*(62)*/{
class Group* gr;
private:
char dname[20]; //department name
Group group[4]; //using Group information
public:
Depart(Group* g);
void setDname(char dname);
void getDname(char *dname);
};
#endif
mistakes:
ac.h(11) : error C2011: 'Student' : 'class' type redefinition
ac.h(49) : error C2011: 'Group' : 'class' type redefinition
ac.h(62) : error C2011: 'Depart' : 'class' type redefinition
i have this 3 definition in other header file in this Program, but there is no any mistakes(i did 'copy-paste' from ac.h to another).
what should i do???
thank you!!!
I'm not quite sure what you're asking but I'm guessing that you've created the above file by copying and pasting from multiple header files. If the above is all in one header file then to fix your errors delete the 4 forward declarations at the top. i.e.
1 2 3 4
class Student;
class Address;
class Group;
class Depart;
Only use forward declarations if you haven't got visibility of the full class definition.
Your comment
i have this 3 definition in other header file in this Program . . .(i did 'copy-paste' from ac.h to another)
implies that you have defined the same class(es) in more than one header file. If this is the case, as a general rule you should not define the same class in more than one place.Try and include the same header file if only to stop having to repeat the same 'fix' in multiple places. Either that or use forward declarations in the header file and include the header file in the source code file (which is always the better way of doing it if you can).