This is the first time I have used classes in C++. This program is fairly simple, I am to create a Student class with 4 instance variables. Then create a default and non-default constructor as well as a member function to display the instance variables. In the main body of my program I declare two objects using the two different constructors, then call the member function in order to display the data. There is something wrong, and as I am a beginner I cannot figure it out for the life of me. I receive two LNK2019: unresolved external symbol errors that are referring to both of my constructors being referenced in my main function. Any help would be greatly appreciated.
// class for college student
class Student
{
public:
// instance/member variables
std::string studentName;
int phoneNumber;
int studentNumber;
double currentGPA;
// member function to display instance variables
void displayValues();
public:
// default constructor that assigns deault values to instance variables
Student() : studentName ("Laura"), phoneNumber (6514923845), studentNumber (0002), currentGPA (3.8) {}
// non default constructor that takes 4 variables as parameters and sets to instance variables
Student(std::string studentName, int phoneNumber, int studentNumber, double currentGPA);
// default deconstrucor
~Student();
};
// non default constructor that takes 4 variables as parameters and sets to instance variables
Student(std::string studentName, int phoneNumber, int studentNumber, double currentGPA);
No implementation here. You could try adding {} but that would be weird, since you'll most likely want to take some operations here.
~Student();
here too. You can actually get rid of this if you wont do anything before the object(in this case the class) destroys.
It might help a little, if I mention to name the header & .cpp files the same as the class. That is Student.h and Student.cpp. Student.cpp has the implementation code for the class functions. Name the file with main in it something else.