Undefined Reference to
Feb 27, 2012 at 6:20pm UTC
Hello, I am having trouble when I compile my program. When i try to create an object from a type i defined in a class i made, this case student, it gives me the undefined error. I'm using a makefile to compile but I don't know it its right since this is the first time i get to use it.
1 2 3
Project1.o: Project1.cpp std_lib_facilities.h Student.h Courses.h StudentCourses.h GroupOfStudents.h Menu.h
g++ Project1.cpp -o Project1.o
This is the .cpp file, I just tried defining an object but it doesnt work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "std_lib_facilities.h"
#include "Student.h"
#include "Courses.h"
#include "StudentCourses.h"
#include "GroupOfStudents.h"
#include "Menu.h"
int main()
{
Student student;
}
Help in this matter would be really appreciated!
Last edited on Feb 28, 2012 at 12:20am UTC
Feb 27, 2012 at 6:31pm UTC
This is the .cpp file, I just tried defining an object but it doesnt work.
I assume the error reads something like
Undefined reference to: Blah
?
That's a linker error, it means you declared something without providing a definition for it (maybe it's in another file). Please post the full error message.
Feb 27, 2012 at 6:53pm UTC
Oh sorry, this is the error message:
In function 'main': undefined reference to 'Student::Student[in-charge]()
collect2: ld returned 1 exit status
Feb 27, 2012 at 10:29pm UTC
This is also what i have for the Student.h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#ifndef _STUDENT_H_
#define _STUDENT_H_
#include "std_lib_facilities.h"
class Student{
public :
Student();
Student(string f, string l, string i)
:firstName(f), lastName(l), ID(i){}
string get_ID(){return ID;};
string get_lastName(){return lastName;};
string get_firstName(){return firstName;};
void display(){ cout << firstName<< " " <<lastName<< " " << ID << endl;};
friend ostream & operator <<(ostream &stream, Student s);
private :
string firstName;
string lastName;
string ID;
};
ostream &operator <<(ostream &stream, Student s)
{
stream << s.firstName << " " ;
stream << s.lastName<< " " ;
stream << s.ID << " " <<endl;
return stream;
}
#endif
Feb 28, 2012 at 1:56am UTC
Found the problem.
Mar 5, 2012 at 11:30pm UTC
hi .. would you please tell me what was the problem
i'm having the same problem in my code
thnx in advance
Topic archived. No new replies allowed.