I am having trouble with inheritance. I am wanting to use fullName.h as the base class and call the functions print and setName into student.h. The problem is that I am getting errors that I can not figure out. The errors are:
student.h(22) : error C2352: 'fullName::print' : illegal call of non-static member function
fullName.h(9) : see declaration of 'fullName::print'
student.h(33) : error C2761: 'void student::setAll(void)' : member function redeclaration not allowed
student.h(34) : error C2447: '{' : missing function header (old-style formal list?)
The code from both header files follows.
fullName.h
//class fullName
#include <iostream>
#include <string>
using namespace std;
class fullName
{
public:
void print() const;
void setName(string f, string l);
string getFirst() const;
string getLast() const;
fullName(string f = "null", string l = "null");
private:
string first;
string last;
};
void fullName::print() const
{
cout << "First Name: " << first << endl;
cout << "Last Name: " << last << endl;
}
void fullName::setName(string f, string l)
{
cout << "Enter your first name: " ;
cin >> first;
cout << "Enter your last name: " ;
cin >> last;
}
string fullName::getFirst() const
{
return first;
}
string fullName::getLast() const
{
return last;
}
/*fullName::fullName(string f, string l)
{
first = f;
last = l;
}
*/
student.h
//class student
#include <iostream>
#include <string>
#include "fullName.h"
class student
{
public:
void print() const;
void setStudentInfo(int n, double g);
void setAll();
int getStudentNumber() const;
double getStudentGPA() const;
private:
int studentNumber;
double GPA;
};
void student::print() const
{
fullName::print();
cout << "Student Number: " << studentNumber << endl;
cout << "GPA: " << GPA << endl;
}
void student::setStudentInfo(int n, double g)
{
studentNumber = n;
GPA = g;
}
void student::setAll();
{
fullName::setName(f, l)
cout << "Enter your student number: ";
cin >> studentNumber;
cout << "Enter your GPA: ";
cin >> GPA;
}
int student::getStudentNumber() const
{
return studentNumber;
}
double student::getStudentGPA() const
{
return GPA;
}
Any help would be greatly appreciated.