Inheritance help

This is a discussion on Inheritance help within the C++ Programming forums, part of the General Programming Boards category; I'm having trouble using inheritance. I have a base class called "Individual", and i have a derived class called "Student". ...

  1. #1
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149

    Inheritance help

    I'm having trouble using inheritance. I have a base class called "Individual", and i have a derived class called "Student". I created the classes and the functions for each, but i am getting the following errors: 'Individual' : 'class' type redefinition, and 'Individual' : base class undefined.
    I think it has something to do with the constructors or with the class itself.
    Header file of base class "Individual":
    Code:
    class Individual
    {                       <----  'Individual' : 'class' type redefinition
    public:
    	Individual(string, string, string);
    private:
    	string Last_Name;
    	string First_Name;
    	string Phone_Number;
    };
    Function file of base class "Individual":
    Code:
    #include "assign4header.h"
    
    Individual::Individual(string LastName, string FirstName, string PhoneNumber)
    {
    	setLast_Name(LastName);
    	setFirst_Name(FirstName);
    	setPhone_Number(PhoneNumber);
    }
    Header file of derived class "Student":
    Code:
    #include "assign4header.h"
    
    class Student : public Individual
    {                       <---------  'Individual' : base class undefined
    public:
    	Student(string, string, string, float, float);
    private:
                    float GPA;
    	float Hours;
    };
    Funtion File of derived class "Student":
    Code:
    #include "assign4header2.h"
    
    Student::Student(string LastName, string FirstName, string PhoneNumber, float GradeAvg, float HoursEnrolled )
    :Individual(LastName, FirstName, PhoneNumber)
    {
    	setGPA(GradeAvg);
    	setHours(HoursEnrolled);
    }
    The base class has members for the last name, first name, and phone number of a person. The derived class has members for the gpa and hours of enrollment of a person. So i should be able to create an object like this in main:
    Code:
    Student("Williams", "John", "555-1234", 4.0, 15.0);
    I have appropriate set and get functions for both classes , but i left them out because i think the problem is with the constructors or class itself. If it is needed, i can put them in.
    Last edited by Cpro; 04-01-2007 at 07:00 PM.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Are you putting semi-colons at the end of your class definitions?
    Code:
    class A{
    public:
        A();
    };
    Woop?

  3. #3
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    Yes, sorry about that, i updated it.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    41
    Header guards?

  5. #5
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    Ahh, that was it. I must have wasted an hour trying to figure out what was wrong, and it was as simple as that. Figures.
    Thank You.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 04:03 PM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 01:46 PM
  4. Inheritance and Polymorphism
    By bench386 in forum C++ Programming
    Replies: 2
    Last Post: 03-18-2004, 10:19 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 04:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21