ciao ragazzi ho scritto un semplice programmino in c++ per testare l'uso dei puntatori e la suddivisione in più file di un progetto. Io utilizzo dev-c++ su windows vista (ovviamente ben configurato). Vi posto i file del mio progetto e l'errore che mi da in compilazione sperando che qualche anima pia mi illustri il problema. Grazie in anticipo.
l'errore riportato è:
I file che fanno parte del progetto sono:codice:3 C:\Users\Gabriele\C++\Department.cpp In file included from ../Users/Gabriele/C++/Department.cpp 8 C:\Users\Gabriele\C++\Department.h expected unqualified-id before "using" 8 C:\Users\Gabriele\C++\Department.h expected `,' or `;' before "using" 7 C:\Users\Gabriele\C++\Department.cpp expected unqualified-id before "using" 7 C:\Users\Gabriele\C++\Department.cpp expected `,' or `;' before "using" C:\Dev-Cpp\Makefile.win [Build Error] n\make.exe: *** [../Users/Gabriele/C++/Department.o] Error 1
1) Department.cpp
2) Department.hcodice:#include <iostream> #include <string> #include "Department.h" #include "Employee.h" using namespace std; Department::Department(string n) { name = n; receptionist = NULL; secretary = NULL; } void Department::set_receptionist(Employee* r) { receptionist = r; } void Department::set_secretary(Employee* s) { secretary = s; } void Department::print() const { cout << "Name: " << name << "\nReceptionist: "; if (receptionist == NULL) cout << "None"; else cout << receptionist->get_name() << " " << receptionist->get_salary(); cout << "\nSecretary: "; if (secretary == NULL) cout << "None"; else cout << secretary->get_name() << " " << secretary->get_salary(); cout << "\n"; }
3) Employee.hcodice:#ifndef DEPARTMENT_H #define DEPARTMENT_H #include <string> #include "Employee.h" using namespace std; class Department { public: Department(string n); void set_receptionist(Employee* r); void set_secretary(Employee* s); void print() const; private: string name; Employee* receptionist; Employee* secretary; } #endif
4) Employee.cppcodice:#ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { public: Employee(); Employee(string employee_name, double initia_salary); void set_salary(double new_salary); string get_name() const; double get_salary() const; private: string name; double salary; } #endif
5) main.cppcodice:#include <string> #include "Employee.h" using namespace std; Employee::Employee(string employee_name, double initial_salary) { name = employee_name; salary = initial_salary; } string Employee::get_name() { return name; } double Employee::get_salary() { return salary; } void Employee::set_salary(double new_salary) { salary = new_salary; }
Grazie mille e scusate la lunghezza del post ma era per dare tutte le info possibili sul codice che ho scritto.codice:#include <iostream> #include <string> #include "Employee.h" #include "Department.h" using namespace std; int main() { Department shipping("Shipping"); Department qc("Quality Control"); Employee* harry = new Employee("Hacker, Harry", 45000); shipping.set_secretary(harry); Employee* tina = new Employee("Tester, Tina", 50000); qc.set_secretary(tina); qc.set_receptionist(tina); tina->set_salary(55000); shipping.print(); qc.print(); return 0; }

Rispondi quotando