Need help with compiler errors for a simple C++ program using strings

My code includes the driver.cpp (main program), Student.h, and Student.cpp files.
Perhaps there is a problem with the implementation of the string _id, _name or the C++ linking library is missing a key ingredient to compile the program and run. (errors after program code)



// file: driver.cpp (main program)

#include "Student.h"

int main()
{
Student student(101, "Tom Lee");

student.display();
return 0;
}

// file: Student.h

#include <iostream>
#include <string>
using namespace std;

#ifdef STUDENT_H
#define STUDENT_H

class Student
{
private:
int _id;
string _name;
public:
Student();
Student(int, string);
~Student();
void display();

};
#endif

// file: Student.cpp

#include <iostream>
#include <string>
using namespace std;

#include "Student.h"
//-----------------------------------
Student::Student(){}
//-----------------------------------
Student::Student(int id, string name)
{
_id = id;
_name = name;

}
//-----------------------------------
Student::~Student(){}
//-----------------------------------
void Student::display()
{
cout << "ID: " >> _id;
cout << endl;
cout << "NAME: " >> _name;
cout << endl;
}
//-----------------------------------

my errors:
driver.cpp: In function ‘int main()’:
driver.cpp:6:3: error: ‘Student’ was not declared in this scope
driver.cpp:6:11: error: expected ‘;’ before ‘student’
driver.cpp:8:3: error: ‘student’ was not declared in this scope
Student.cpp:7:1: error: ‘Student’ does not name a type
Student.cpp:9:1: error: ‘Student’ does not name a type
Student.cpp:16:1: error: ‘Student’ does not name a type
Student.cpp:18:6: error: ‘Student’ has not been declared
Student.cpp: In function ‘void display()’:
Student.cpp:20:21: error: ‘_id’ was not declared in this scope
Student.cpp:22:23: error: ‘_name’ was not declared in this scope
#ifdef STUDENT_H means " if STUDENT_H is already defined, ... ". What you need is #ifndef
Topic archived. No new replies allowed.