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 è:
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
I file che fanno parte del progetto sono:
1) Department.cpp
codice:
#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";
}
2) Department.h
codice:
#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
3) Employee.h
codice:
#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
4) Employee.cpp
codice:
#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;
}
5) main.cpp
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;
}
Grazie mille e scusate la lunghezza del post ma era per dare tutte le info possibili sul codice che ho scritto.