I'm having an issue with classes in that my IDE tells me that I have an undefined reference to my constructor if I include my .hpp file in main, but not if I include my .cpp file in main instead. My problem is that in class and across various sites, it should be the .h or .hpp file included in the main. Here are my files:
Student.hpp
#ifndef STUDENT_HPP
#define STUDENT_HPP
class Student
{
private:
std::string lastName;
double gpa;
public:
Student();
Student(std::string LastName, double Gpa);
void setLastName(std::string LastName);
std::string getLastName();
void setGpa(double Gpa);
double getGpa();
};
#endif //STUDENT_HPP
Student.cpp
#include <iostream>
#include "Student.hpp"
using namespace std;
Student::Student()
{
lastName = "unknown";
gpa = 0.0;
}
Student::Student(string LastName, double Gpa)
{
lastName = LastName;
gpa = Gpa;
}
void Student::setLastName(string LastName)
{
lastName = LastName;
}
string Student::getLastName()
{
return lastName;
}
void Student::setGpa(double Gpa)
{
gpa = Gpa;
}
double Student::getGpa()
{
return gpa;
}
main.cpp
#include <iostream>
#include "Student.hpp"
using namespace std;
int main()
{
Student liz = Student();
cout << liz.getLastName() << endl;
return 0;
}
Thanks for your help.
Edit: This doesn't appear to be a duplicate to me, I don't even have the ability at this point to really understand the linked page. If it somehow says the same thing, it's in another language to me and I still needed the help.