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.

You need to create an instance of fullName inside your 'student' class. You're trying to call the functions, but there's nowhere for the data to go.

You need to create an instance of fullName inside your 'student' class. You're trying to call the functions, but there's nowhere for the data to go.

Thanks!! It's always the simplest things. I can't believe I forgot that.

I am still getting the following error:
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?)

Any ideas?

Thanks!! It's always the simplest things. I can't believe I forgot that.

D'oh! I forgot this was supposed to be inheritance. In that case, what you need to do is make student a derived class of fullName . Then the erorrs will go away, and you're actually using inheritance to solve the problem.

I am still getting the following error:
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?)

Remove the semicolon here:

void student::setAll();
{
commented: Very quick to respond! +1

D'oh! I forgot this was supposed to be inheritance. In that case, what you need to do is make student a derived class of fullName . Then the erorrs will go away, and you're actually using inheritance to solve the problem.


Remove the semicolon here:

void student::setAll();
{

Ugh, again something simple I should have caught. Maybe I should learn when to get up, take a break, and revisit it at a later time.
Thanks again, problem solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.