I'm trying to write a program which uses 4 class files. However, I've got some issue regarding the error I got from cygwin using g++ command, it says Calling fdopen: bad file descriptor when I try to include the files I need on top of my header files. I'll show all my codes here:
4 class files and 4 cpp files are shown here.
Anyways, it would be great if someone could see if I'm doing wrong with the header. I've been getting all sorts of errors by just compiling and linking all files together(I created an empty
int main(){}
in each cpp files just for the sake of compiling)
My main problem is when I tried to add files in both .h and .cpp files, the compiler complaints and even give me undefined reference despite the appropriate files are added.
#ifndef DIVISIONLIST_H
#define DIVISIONLIST_H
#include "DivisionNode.h"
#include "EmployeeNode.h"
using namespace std;
class DivisionList{
public:
DivisionList();
~DivisionList();
bool newDivision(int divNum);
bool newEmployee(int emplNum,int divNum,char *firstName,char *lastName,double hours,double hourlyWage,int &error);
bool deleteDivision(int divNum);
EmployeeNode *locateEmployee(int emplNum);
bool locateEmployee(int emplNum,int &divNum,char*& firstName,char*& lastName);
bool deleteEmployee(int emplNum);
void printDivision(int divNum);
void printAll();
void insertDivisionNode(int divNum);
private:
DivisionNode* head;
};
#endif
#ifndef DIVISIONNODE_H
#define DIVISIONNODE_H
#include "EmployeeNode.h"
#include "EmployeeList.h"
using namespace std;
class DivisionNode {
public:
DivisionNode();
DivisionNode(int divNum);
~DivisionNode();
int getDivisionNum();
DivisionNode* getNext();
void setDivisionNum(int divNum);
void setNext(DivisionNode* n);
bool newEmployee(int emplNum,char* firstName,char* lastName,double hours,double wourlyWage);
EmployeeNode* locateEmployee(int emplNum);
bool locateEmployee(int emplNum,char*& firstName,char*& lastName);
bool deleteEmployee(int emplNum);
void printEmployees();
private:
int divisionNum;
EmployeeList employees;
DivisionNode* next;
};
#endif
#ifndef EMPLOYEELIST_H
#define EMPLOYEELIST_H
#include "DivisionNode.h"
#include "EmployeeNode.h"
using namespace std;
class EmployeeList{
public:
EmployeeList();
~EmployeeList();
EmployeeNode *getHead();
void setHead( EmployeeNode *n);
bool newEmployee(int emplNum,char* firstName,char* lastName,double hrs,double hourlyWage);
EmployeeNode* locateEmployee(int emplNum);
bool locateEmployee(int emplNum,char*& firstName,char*& lastName);
bool deleteEmployee(int emplNum);
void printEmployees();
void insertEmployee(int emplNum,char* firstName,char* lastName,double hrs,double hourlyWage);
private:
EmployeeNode* head;
};
#endif
#ifndef EMPLOYEENODE_H
#define EMPLOYEENODE_H
using namespace std;
class EmployeeNode {
public:
EmployeeNode();
EmployeeNode(int emplNum,char* fName,char* lName,double hourlyWage,double hrs,EmployeeNode* n);
~EmployeeNode();
int getEmplNumber();
char *getFirstName();
char* getLastName();
double getHourlyWage();
double getHours();
EmployeeNode *getNext();
void setEmplNum(int emplNum);
void setFirstName(char *fname);
void setLastName(char *lname);
void setHourlyWage(double hourlyWage);
void setHours(double h);
void setNext(EmployeeNode* n);
void print();
private:
int employeeNumber;
char* firstName;
char* lastName;
double wage;
double hours;
EmployeeNode* next;
};
#endif
cpp files
DivisionList.cpp
#include "DivisionList.h"
#include "EmployeeNode.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){
}
DivisionList::DivisionList(){
}
DivisionList::~DivisionList(){
}
bool DivisionList::newDivision(int divNum){
EmployeeNode *p;
}
EmployeeNode* DivisionList::locateEmployee(int emplNum){
}
bool DivisionList::newEmployee(int emplNum,int divNum,char *firstName,char *lastName,double hours,double hourlyWage,int &error){
}
bool DivisionList::deleteDivision(int divNum){
}
bool DivisionList::locateEmployee(int emplNum,int &divNum,char*& firstName,char*& lastName){
}
bool DivisionList::deleteEmployee(int emplNum){
}
void DivisionList::printDivision(int divNum){
}
void DivisionList::printAll(){
}
void DivisionList::insertDivisionNode(int divNum){
}
DivisionNode.cpp
#include "DivisionNode.h"
#include "EmployeeList.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){}
DivisionNode::DivisionNode():divisionNum(0),next(NULL){
//deliberately empty
}
DivisionNode::DivisionNode(int divNum):divisionNum(divNum),next(NULL) {
//deliberately empty
}
DivisionNode::~DivisionNode(){
}
int DivisionNode::getDivisionNum(){
return divisionNum;
}
DivisionNode* DivisionNode::getNext(){
return next;
}
void DivisionNode::setDivisionNum(int divNum){
divisionNum = divNum;
}
void DivisionNode::setNext(DivisionNode* n){
next = n;
}
bool newEmployee(int emplNum,char* firstName,char* lastName,double hours,double wourlyWage){
}
EmployeeNode* DivisionNode::locateEmployee(int emplNum){
}
bool DivisionNode::locateEmployee(int emplNum,char*& firstName,char*& lastName){
}
bool DivisionNode::deleteEmployee(int emplNum){
}
void DivisionNode::printEmployees(){
}
EmployeeList.cpp
#include "EmployeeList.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){}
EmployeeList::EmployeeList(){
}
EmployeeList:: ~EmployeeList(){
}
EmployeeNode* EmployeeList::getHead(){
return head;
}
void EmployeeList::setHead(EmployeeNode *n){
head = n;
}
bool EmployeeList::newEmployee(int emplNum,char* firstName,char* lastName,double hrs,double hourlyWage){
}
EmployeeNode* EmployeeList::locateEmployee(int emplNum){
}
bool EmployeeList::locateEmployee(int emplNum,char*& firstName,char*& lastName){
EmployeeList fname;
if(locateEmployee(emplNum) == NULL) return false;
else {
return true;
}
}
bool EmployeeList::deleteEmployee(int emplNum){
}
void EmployeeList::printEmployees(){
}
void insertEmployee(int emplNum,char* firstName,char* lastName,double hrs,double hourlyWage,EmployeeNode* next){
}
EmployeeNode.cpp
#include "EmployeeNode.h"
#include <iostream>
#include <string>
#include <cstring>
int main(){}
using namespace std;
EmployeeNode::EmployeeNode(){
}
EmployeeNode::EmployeeNode(int emplNum,char* fName,char* lName,double hourlyWage,double hrs,EmployeeNode* n){
}
EmployeeNode::~EmployeeNode(){
}
int EmployeeNode::getEmplNumber(){
return employeeNumber;
}
char* EmployeeNode::getFirstName(){
return firstName;
}
char* EmployeeNode::getLastName(){
return lastName;
}
double EmployeeNode::getHourlyWage(){
return wage;
}
double EmployeeNode::getHours(){
return hours;
}
EmployeeNode* EmployeeNode::getNext(){
return next;
}
void EmployeeNode::setEmplNum(int emplNum){
employeeNumber = emplNum;
}
void EmployeeNode::setFirstName(char *fname){
strcpy(firstName,fname);
}
void EmployeeNode::setLastName(char *lname){
strcpy(lastName,lname);
}
void EmployeeNode::setHourlyWage(double hourlyWage){
wage = hourlyWage;
}
void EmployeeNode::setHours(double h){
hours = h;
}
void EmployeeNode::setNext(EmployeeNode* n){
next = n;
}
In my divisionNode.cpp file, wouldn't it makes more sense if I include the 2 files(EmployeeList.h and DivisionNode.h), since divisionNode class is using
EmployeeList employees
and
DivisionNode* next;
respectively. However, I got bad file descriptor error. I tried switching the order of the 2 lines(#include "EmployeeList.h" and #include"DivisionNode.h" but
still, no luck.
There are few major problems when I tried to compile each individual file:
Beaten@Beaten-PC ~
$ g++ EmployeeList.h
In file included from EmployeeList.h:5:
DivisionNode.h:4:26: calling fdopen: Bad file descriptor
In file included from EmployeeList.h:5:
DivisionNode.h:42: error: `EmployeeList' does not name a type
Beaten@Beaten-PC ~
$ g++ divisionNode.h
In file included from divisionNode.h:5:
EmployeeList.h:4:26: calling fdopen: Bad file descriptor
Beaten@Beaten-PC ~
$ g++ DivisionNode.cpp
/cygdrive/c/Users/Beaten/AppData/Local/Temp/ccyxTy3W.o:DivisionNode.cpp:(.text+0x
14b): undefined reference to `EmployeeList::EmployeeList()'
/cygdrive/c/Users/Beaten/AppData/Local/Temp/ccyxTy3W.o:DivisionNode.cpp:(.text+0x
175): undefined reference to `EmployeeList::EmployeeList()'
/cygdrive/c/Users/Beaten/AppData/Local/Temp/ccyxTy3W.o:DivisionNode.cpp:(.text+0x
19e): undefined reference to `EmployeeList::EmployeeList()'
/cygdrive/c/Users/Beaten/AppData/Local/Temp/ccyxTy3W.o:DivisionNode.cpp:(.text+0x
1c6): undefined reference to `EmployeeList::EmployeeList()'
/cygdrive/c/Users/Beaten/AppData/Local/Temp/ccyxTy3W.o:DivisionNode.cpp:(.text+0x
1e6): undefined reference to `EmployeeList::~EmployeeList()'
/cygdrive/c/Users/Beaten/AppData/Local/Temp/ccyxTy3W.o:DivisionNode.cpp:(.text+0x
1fc): undefined reference to `EmployeeList::~EmployeeList()'
collect2: ld returned 1 exit status
Any ideas where am I doing wrong here? Should I create my own namespace or, use makefiles etc? Are the ordering of my header files important? Is file dependencies a really big issue here? Any help will be greatly appreciated. Can you guys give me the correct sequence of #include "somefiles.h" to be put into my header files? So that I can get rid of the errors. Help, I've been stuck with this for a few hours! Thanks a lot!!