Inheritance problems?

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 579 Views - Last Post: 04 August 2013 - 01:42 PM Rate Topic: -----

#1 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Inheritance problems?

Posted 01 August 2013 - 07:11 PM

I keep getting these errors:

In file included from people.h:6:0,
from main.cc:3:
gender.h:7:28: error: invalid use of incomplete type 'struct people'
gender.h:5:7: error: forward declaration of 'struct people'
gender.h: In member function 'double male::bmr()':
gender.h:10:11: error: aggregate 'people p' has incomplete type and cannot be defined
gender.h: At global scope:
gender.h:29:30: error: invalid use of incomplete type 'struct people'
gender.h:5:7: error: forward declaration of 'struct people'
gender.h: In member function 'double female::bmr()':
gender.h:32:11: error: aggregate 'people p' has incomplete type and cannot be defined

Here are the beginnings of my classes:

#ifndef PEOPLE_H
#define PEOPLE_H
#include <iostream>
#include <string>
#include "date.h"
#include "gender.h"
#include "base.h"

class people {
        public:
                people() : height(0), weight(0), a(0) {}



#ifndef MALE_H
#define MALE_H
#include <iostream>

class people;

class male : public people {



#ifndef FEMALE_H
#define FEMALE_H
#include <iostream>

class people;

class female : public people {



#ifndef BASE_H
#define BASE_H
#include <iostream>
#define SE 1.2
#define LA 1.35
#define MA 1.55
#define HA 1.725

class base : public male, public female {



I don't think there are any circular dependencies happening and I forward declare people where I need it so what is wrong? It won't compile because of the errors obviously.

This post has been edited by jordannn15: 01 August 2013 - 07:13 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Inheritance problems?

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,346
  • Joined: 25-December 09

Re: Inheritance problems?

Posted 01 August 2013 - 07:49 PM

Please post the complete gender.h file.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Re: Inheritance problems?

Posted 01 August 2013 - 08:05 PM

#ifndef MALE_H
#define MALE_H
#include <iostream>

class people;

class male : public people {
        public:
                double bmr(){
                        people p;

                        p.input(std::cin);
                        m = 66 + (6.3 * p.weight) + (12.9 * p.height) - (6.8 * p.a);
                        return m;
                }

        protected:
                double m;
};

#endif

#ifndef FEMALE_H
#define FEMALE_H
#include <iostream>

class people;

class female : public people {
        public:
                double bmr(){
                        people p;

                        p.input(std::cin);
                        f = 65 + (4.3 * p.weight) + (4.7 * p.height) - (4.7 * p.a);
                        return f;
                }

        protected:
                double f;
};

#endif


Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,346
  • Joined: 25-December 09

Re: Inheritance problems?

Posted 01 August 2013 - 08:10 PM

Okay I'll also need the people class definition. It would be easier to see the complete program.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Re: Inheritance problems?

Posted 01 August 2013 - 08:18 PM

#ifndef PEOPLE_H
#define PEOPLE_H
#include <iostream>
#include <string>
#include "date.h"
#include "gender.h"
#include "base.h"

class people {
        public:
                people() : height(0), weight(0), a(0) {}

                virtual double bmr() = 0;

                int age(){
                        Date today;
                        Date bday = month + '/' + day + '/' + year;
                        today = 7/30/2013;

                        a = today.age(bday);
                        return a;
                }

                void input(std::istream& ins){
                        if(ins == std::cin){
                                std::cout << "Enter your name: ";
                                if(ins.peek() == '\n') ins.ignore();
                                getline(ins, name);
                                if(ins.eof()) return;
                                std::cout << "Enter birthdate (m/dd/yyyy): ";
                                ins >> month;
                                ins.ignore();
                                ins >> day;
                                ins.ignore();
                                ins >> year;
                                ins.ignore();
                                if(ins.eof()) return;
                                std::cout << "Enter height in inches: ";
                                ins >> height;
                                ins.ignore();
                                ins >> weight;
                                ins.ignore();
                        }else{
                                if(ins.peek() == '\n') ins.ignore();
                                getline(ins, name);
                                if(ins.eof()) return;
                                ins >> month;
                                ins.ignore();
                                ins >> day;
                                ins.ignore();
                                ins >> year;
                                ins.ignore();
                                ins >> height;
                                ins.ignore();
                                ins >> weight;
                        }
                }

                void output(std::ostream& outs){
                        base b;

                        if(outs == std::cout){
                                outs << "Your BMR is " << bmr() << std::endl;
                                outs << "Your suggested calorie intake is " << b.get_cal_intake() << std::endl;
                        }else{
                                outs << bmr() << std::endl;
                                outs << b.get_cal_intake() << std::endl;
                        }
                }

                void set_height(int h) {height = h;}
                void set_weight(int w) {weight = w;}

                int get_height() const{return height;}
                int get_weight() const{return weight;}

        protected:
                int height;
                int weight;
                int a;

        private:
                std::string name;
                int month;
                int day;
                int year;
};

std::istream& operator >>(std::istream& ins, people& p){
        p.input(ins);
        return(ins);
}

std::ostream& operator <<(std::ostream& outs, people& p){
        p.output(outs);
        return(outs);
}

#endif



#ifndef BASE_H
#define BASE_H
#include <iostream>
#define SE 1.2
#define LA 1.35
#define MA 1.55
#define HA 1.725

class base : public male, public female {
        public:
                double dci(char &g){
                        char level;

                        std::cout << "What is your level of activity? Sedentary, lightly, moderately, or highly active?\n";
                        std::cout << "Enter your choice(s, l, m, or h): ";
                        std::cin >> level;
                        level = (char) toupper(level);
                        std::cin.ignore();

                        if(g == 'M'){
                                if(level == 'S')
                                        cal_intake = m * SE;
                                else if(level == 'L')
                                        cal_intake = m * LA;
                                else if(level == 'M')
                                        cal_intake = m * MA;
                                else if(level == 'H')
                                        cal_intake = m * HA;

                        }else if(g == 'F'){
                                if(level == 'S')
                                        cal_intake = m * SE;
                                else if(level == 'L')
                                        cal_intake = m * LA;
                                else if(level == 'M')
                                        cal_intake = m * MA;
                                else if(level == 'H')
                                        cal_intake = m * HA;

                        }else if(g == 'F'){
                                if(level == 'S')
                                        cal_intake = f * SE;
                                else if(level == 'L')
                                        cal_intake = f * LA;
                                else if(level == 'M')
                                        cal_intake = f * MA;
                                else if(level == 'H')
                                        cal_intake = f * HA;
                        }

                        return cal_intake;
                }

                void set_cal_intake(double ci) {cal_intake = ci;}
                double get_cal_intake() {return cal_intake;}

        private:
                double cal_intake;
};

#endif



#include <iostream>
#include "people.h"
#include "gender.h"
#include "base.h"

int main(){
        male m;
        female f;
        char gender;
        char choice;

        do
        {
                std::cout << "Enter your gender(m/f): ";
                std::cin >> gender;
                gender = (char) toupper(gender);
                std::cin.ignore('\n');

                if(gender == 'M')
                        m.bmr();
                else if(gender == 'F')
                        f.bmr();

                std::cout << "Would you like to run the program again(y/n)?\n";
                std::cout << "Enter your choice ->   ";
                std::cin >> choice;
                choice = (char) toupper(choice);
                std::cin.ignore('\n');

        }while(choice != 'N');

        return 0;
}


Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is online

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,346
  • Joined: 25-December 09

Re: Inheritance problems?

Posted 01 August 2013 - 08:39 PM

You're going to find it hard to use forward declaration when everything is contained in the class. I recommend you first break the declaration and implementations into separate .h and .cpp files. But looking at your class layouts I doubt forward declarations will work.

You may want to read the following link it tells you a little more about this subject.

Jim
Was This Post Helpful? 1
  • +
  • -

#7 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Re: Inheritance problems?

Posted 03 August 2013 - 02:22 PM

I have rewritten this program so I have .h and .cc files now so it is cleaner and easier to understand but I still get the following errors and this subject is new to me obviously so I don't know what they mean yet.

#ifndef PEOPLE_H
#define PEOPLE_H
#include <iostream>
#include <string>
#include "date.h"
#include "male.h"
#include "female.h"

class people {
        public:
                people() : height(0), weight(0), old(0) {}

                int cold();

                virtual double bmr() = 0;

                void input(std::istream& ins);
                void output(std::ostream& outs);

                void set_height(int h){height = h;}
                void set_weight(int w){weight = w;}
                void set_old(int o){old = o;}

                int get_height(){return height;}
                int get_weight(){return weight;}
                int get_old(){return old;}

        private:
                int height;
                int weight;
                int old;
                int month;
                int day;
                int year;
                std::string name;
};

std::istream& operator >>(std::istream& ins, people& p){
        p.input(ins);
        return ins;
}

std::ostream& operator <<(std::ostream& outs, people& p){
        p.output(outs);
        return outs;
}

#endif



#include <iostream>
#include <string>
#include "people.h"
#include "date.h"
#include "base.h"

int people::cold(){
        Date today;
        Date bday;

        today = 7/30/2013;
        bday = month + '/' + day + '/' + year;

        old = today.age(bday);

        return old;
}

void people::input(std::istream& ins){
        if(ins == std::cin){
                std::cout << "Enter your name: ";
                if(ins.peek() == '\n') ins.ignore();
                std::getline(ins, name);
                if(ins.eof()) return;
                std::cout << "Enter your birthdate (m/dd/yyyy): ";
                ins >> month;
                if(ins.eof()) return;
                if(ins.peek() == '/') ins.ignore();
                ins >> day;
                if(ins.eof()) return;
                if(ins.peek() == '/') ins.ignore();
                ins >> year;
                if(ins.eof()) return;
                if(ins.peek() == '\n') ins.ignore();
                std::cout << "Enter your height in inches: ";
                ins >> height;
                if(ins.eof()) return;
                if(ins.peek() == '\n') ins.ignore();
                std::cout << "Enter your weight in pounds: ";
                if(ins.eof()) return;
                if(ins.peek() == '\n') ins.ignore();
        }else{
                if(ins.peek() == '\n') ins.ignore();
                std::getline(ins, name);
                if(ins.eof()) return;
                ins >> month;
                if(ins.peek() == '/') ins.ignore();
                if(ins.eof()) return;
                ins >> day;
                if(ins.peek() == '/') ins.ignore();
                if(ins.eof()) return;
                ins >> year;
                if(ins.peek() == '\n') ins.ignore();
                if(ins.eof()) return;
                ins >> height;
                if(ins.peek() == '\n') ins.ignore();
                if(ins.eof()) return;
                ins >> weight;
                if(ins.peek() == '\n') ins.ignore();
                if(ins.eof()) return;
        }
}

void people::output(std::ostream& outs){
        base b;

        if(outs == std::cout){
                outs << "Your BMR is " << bmr() << std::endl;
                outs << "Your suggested calorie intake is " << b.get_cal() << std::endl;
        }else{
                outs << bmr() << std::endl;
                outs << b.get_cal() << std::endl;
        }
}



#ifndef MALE_H
#define MALE_H
#include <iostream>
#include "people.h"

class male : public people {
        public:
                male() : m(0) {}

                double bmr();

                void set_m(double x){m = x;}
                double get_m(){return m;}

        private:
                double m;
};

#endif



#include <iostream>
#include "male.h"
#include "people.h"

double male::bmr(){
        people p;

        p.input(std::cin);
        m = 66 + (6.3 * p.get_weight()) + (12.9 * p.get_height()) - (6.8 * p.get_old());

        return m;
}



#ifndef FEMALE_H
#define FEMALE_H
#include <iostream>
#include "people.h"

class female : public people {
        public:
                female() : f(0) {}

                double bmr();

                void set_f(double x){f = x;}
                double get_f(){return f;}

        private:
                double f;
};

#endif



#include <iostream>
#include "female.h"
#include "people.h"

double female::bmr(){
        people p;

        p.input(std::cin);
        f = 65 + (4.3 * p.get_weight()) + (4.7 * p.get_height()) - (4.7 * p.get_old());

        return f;
}



#ifndef BASE_H
#define BASE_H
#include <iostream>
#include "male.h"
#include "female.h"
#include "people.h"

class base {
        public:
                base() : cal(0) {}

                double dci(char& g);

                void set_cal(double c){cal = c;}
                double get_cal(){return cal;}

        private:
                double cal;
};

#endif



#include <iostream>
#include "base.h"
#include "male.h"
#include "female.h"
#include "people.h"
#define SE 1.2
#define LA 1.35
#define MA 1.55
#define HA 1.725

double base::dci(char& g){
        char level;
        male mb;
        female fb;
        people p;

        std::cout << "Enter your physical activity level(s, l, m, or h): ";
        std::cin >> level;
        if(std::cin.peek() == '\n') std::cin.ignore();
        level = (char) toupper(level);

        if(g == 'M'){
                if(level == 'S')
                        cal = mb.get_m() * SE;
                else if(level == 'L')
                        cal = mb.get_m() * LA;
                else if(level == 'M')
                        cal = mb.get_m() * MA;
                else if(level == 'H')
                        cal = mb.get_m() * HA;
        }else if(g == 'F'){
                if(level == 'S')
                        cal = fb.get_f() * SE;
                else if(level == 'L')
                        cal = fb.get_f() * LA;
                else if(level == 'M')
                        cal = fb.get_f() * MA;
                else if(level == 'H')
                        cal = fb.get_f() * HA;
        }

        p.output(std::cout);

        return cal;
}



#include <iostream>
#include "date.h"
#include "people.h"
#include "male.h"
#include "female.h"
#include "base.h"

int main(){
        char gender;
        char choice;
        male obj;
        female obj1;
        base b;

        do
        {
                std::cout << "Enter your gender(m/f): ";
                std::cin >> gender;
                if(std::cin.peek() == '\n') std::cin.ignore();
                gender = (char) toupper(gender);

                if(gender == 'M'){
                        obj.bmr();
                        b.dci(gender);
                }else if(gender == 'F'){
                        obj1.bmr();
                        b.dci(gender);
                }

                std::cout << "Would you like to run the program again(y/n): ";
                std::cin >> choice;
                if(std::cin.peek() == '\n') std::cin.ignore();
                choice = (char) toupper(gender);

        }while(choice != 'N');

        return 0;
}



Errors:

In file included from people.h:7:0,
from male.h:4,
from base.h:4,
from base.cc:2:
female.h:6:30: error: expected class-name before '{' token
base.cc: In member function 'double base::dci(char&)':
base.cc:15:9: error: cannot declare variable 'p' to be of abstract type 'people'
people.h:9:14: note: because the following virtual functions are pure within 'people':
people.h:15:18: note: virtual double people::bmr()
In file included from people.h:6:0,
from female.h:4,
from female.cc:2:
male.h:6:28: error: expected class-name before '{' token
female.cc: In member function 'virtual double female::bmr()':
female.cc:6:9: error: cannot declare variable 'p' to be of abstract type 'people'
people.h:9:14: note: because the following virtual functions are pure within 'people':
people.h:15:18: note: virtual double people::bmr()
In file included from people.h:6:0,
from main.cc:3:
male.h:6:28: error: expected class-name before '{' token
In file included from people.h:7:0,
from main.cc:3:
female.h:6:30: error: expected class-name before '{' token
In file included from people.h:7:0,
from male.h:4,
from male.cc:2:
female.h:6:30: error: expected class-name before '{' token
male.cc: In member function 'virtual double male::bmr()':
male.cc:6:9: error: cannot declare variable 'p' to be of abstract type 'people'
people.h:9:14: note: because the following virtual functions are pure within 'people':
people.h:15:18: note: virtual double people::bmr()
In file included from people.h:6:0,
from people.cc:3:
male.h:6:28: error: expected class-name before '{' token
In file included from people.h:7:0,
from people.cc:3:
female.h:6:30: error: expected class-name before '{' token
Was This Post Helpful? 0
  • +
  • -

#8 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Re: Inheritance problems?

Posted 03 August 2013 - 03:18 PM

If I change line 15 in people.h to virtual double bmr(); instead of virtual double bmr() = 0; I only get these errors:

In file included from people.h:7:0,
from male.h:4,
from base.h:4,
from base.cc:2:
female.h:6:30: error: expected class-name before '{' token
In file included from people.h:6:0,
from female.h:4,
from female.cc:2:
male.h:6:28: error: expected class-name before '{' token
In file included from people.h:6:0,
from main.cc:3:
male.h:6:28: error: expected class-name before '{' token
In file included from people.h:7:0,
from main.cc:3:
female.h:6:30: error: expected class-name before '{' token
In file included from people.h:7:0,
from male.h:4,
from male.cc:2:
female.h:6:30: error: expected class-name before '{' token
In file included from people.h:6:0,
from people.cc:3:
male.h:6:28: error: expected class-name before '{' token
In file included from people.h:7:0,
from people.cc:3:
female.h:6:30: error: expected class-name before '{' token
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3530
  • View blog
  • Posts: 10,931
  • Joined: 05-May 12

Re: Inheritance problems?

Posted 03 August 2013 - 04:01 PM

You have a circular dependency in your header files. people.h includes male.h and female.h, but those header files include people.h.
Was This Post Helpful? 0
  • +
  • -

#10 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 651
  • View blog
  • Posts: 2,240
  • Joined: 31-December 10

Re: Inheritance problems?

Posted 03 August 2013 - 07:25 PM

You use forward declarations when you know all you will be dealing with is pointers to that type. That way the compiler doesn't need to know about the class. The compiler does need to know about the class when you use it to derive from or instantiate objects/call member functions.
Was This Post Helpful? 0
  • +
  • -

#11 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Re: Inheritance problems?

Posted 03 August 2013 - 08:56 PM

If I change male.h and female.h so it doesn't include people.h and I change it to a forward declaration like this:

#ifndef FEMALE_H
#define FEMALE_H
#include <iostream>

class people;

class female : public people {
        public:
                female() : f(0) {}

                double bmr();

                void set_f(double x){f = x;}
                double get_f(){return f;}

        private:
                double f;
};

#endif



#ifndef MALE_H
#define MALE_H
#include <iostream>

class people;

class male : public people {
        public:
                male() : m(0) {}

                double bmr();

                void set_m(double x){m = x;}
                double get_m(){return m;}

        private:
                double m;
};

#endif



I get these errors:

In file included from base.h:4:0,
from base.cc:2:
male.h:7:28: error: invalid use of incomplete type 'struct people'
male.h:5:7: error: forward declaration of 'struct people'
In file included from base.h:5:0,
from base.cc:2:
female.h:7:30: error: invalid use of incomplete type 'struct people'
male.h:5:7: error: forward declaration of 'struct people'
In file included from female.cc:2:0:
female.h:7:30: error: invalid use of incomplete type 'struct people'
female.h:5:7: error: forward declaration of 'struct people'
female.cc: In member function 'double female::bmr()':
female.cc:5:9: error: aggregate 'people p' has incomplete type and cannot be defined
In file included from people.h:6:0,
from main.cc:3:
male.h:7:28: error: invalid use of incomplete type 'struct people'
male.h:5:7: error: forward declaration of 'struct people'
In file included from people.h:7:0,
from main.cc:3:
female.h:7:30: error: invalid use of incomplete type 'struct people'
male.h:5:7: error: forward declaration of 'struct people'
In file included from male.cc:2:0:
male.h:7:28: error: invalid use of incomplete type 'struct people'
male.h:5:7: error: forward declaration of 'struct people'
male.cc: In member function 'double male::bmr()':
male.cc:5:9: error: aggregate 'people p' has incomplete type and cannot be defined
In file included from people.h:6:0,
from people.cc:3:
male.h:7:28: error: invalid use of incomplete type 'struct people'
male.h:5:7: error: forward declaration of 'struct people'
In file included from people.h:7:0,
from people.cc:3:
female.h:7:30: error: invalid use of incomplete type 'struct people'
male.h:5:7: error: forward declaration of 'struct people'

Then if I change them so they aren't including people.h and no forward declaration like this:

#ifndef MALE_H
#define MALE_H
#include <iostream>

class male : public people {
        public:
                male() : m(0) {}

                double bmr();

                void set_m(double x){m = x;}
                double get_m(){return m;}

        private:
                double m;
};

#endif



#ifndef FEMALE_H
#define FEMALE_H
#include <iostream>

class female : public people {
        public:
                female() : f(0) {}

                double bmr();

                void set_f(double x){f = x;}
                double get_f(){return f;}

        private:
                double f;
};

#endif



I get these errors:

In file included from base.h:4:0,
from base.cc:2:
male.h:5:28: error: expected class-name before '{' token
In file included from base.h:5:0,
from base.cc:2:
female.h:5:30: error: expected class-name before '{' token
In file included from female.cc:2:0:
female.h:5:30: error: expected class-name before '{' token
female.cc: In member function 'double female::bmr()':
female.cc:5:2: error: 'people' was not declared in this scope
female.cc:5:9: error: expected ';' before 'p'
female.cc:7:2: error: 'p' was not declared in this scope
In file included from people.h:6:0,
from main.cc:3:
male.h:5:28: error: expected class-name before '{' token
In file included from people.h:7:0,
from main.cc:3:
female.h:5:30: error: expected class-name before '{' token
In file included from male.cc:2:0:
male.h:5:28: error: expected class-name before '{' token
male.cc: In member function 'double male::bmr()':
male.cc:5:2: error: 'people' was not declared in this scope
male.cc:5:9: error: expected ';' before 'p'
male.cc:7:2: error: 'p' was not declared in this scope
In file included from people.h:6:0,
from people.cc:3:
male.h:5:28: error: expected class-name before '{' token
In file included from people.h:7:0,
from people.cc:3:
female.h:5:30: error: expected class-name before '{' token

This post has been edited by jordannn15: 03 August 2013 - 08:56 PM

Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg  Icon User is online

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,346
  • Joined: 25-December 09

Re: Inheritance problems?

Posted 03 August 2013 - 09:30 PM

You need to #include "people.h" in these files. But you shouldn't need to include these files in people.h.

These files need to know what a "people" is, but "people" doesn't need to know what "male" or "female" is.

Jim
Was This Post Helpful? 0
  • +
  • -

#13 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Re: Inheritance problems?

Posted 03 August 2013 - 09:41 PM

Okay that helped but I still get errors about expected class name before '{' token:

In file included from base.h:4:0,
from people.h:6,
from female.h:4,
from female.cc:2:
male.h:6:28: error: expected class-name before '{' token
In file included from base.h:4:0,
from people.h:6,
from main.cc:3:
male.h:6:28: error: expected class-name before '{' token
In file included from base.h:5:0,
from people.h:6,
from main.cc:3:
female.h:6:30: error: expected class-name before '{' token
In file included from base.h:5:0,
from people.h:6,
from male.h:4,
from male.cc:2:
female.h:6:30: error: expected class-name before '{' token
In file included from base.h:4:0,
from people.h:6,
from people.cc:3:
male.h:6:28: error: expected class-name before '{' token
In file included from base.h:5:0,
from people.h:6,
from people.cc:3:
female.h:6:30: error: expected class-name before '{' token

This post has been edited by jordannn15: 03 August 2013 - 09:41 PM

Was This Post Helpful? 0
  • +
  • -

#14 jimblumberg  Icon User is online

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,346
  • Joined: 25-December 09

Re: Inheritance problems?

Posted 03 August 2013 - 09:53 PM

Well base doesn't need to know about people, male or female so start by removing the includes in that file.

Next do all of your include files have include guards?

Jim
Was This Post Helpful? 0
  • +
  • -

#15 jordannn15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 213
  • Joined: 06-July 12

Re: Inheritance problems?

Posted 03 August 2013 - 10:11 PM

Okay after removing the included people.h, male and female.h now it is complaining about them not being declared in this scope:

base.cc: In member function 'double base::dci(char&)':
base.cc:10:2: error: 'male' was not declared in this scope
base.cc:10:7: error: expected ';' before 'mb'
base.cc:11:2: error: 'female' was not declared in this scope
base.cc:11:9: error: expected ';' before 'fb'
base.cc:12:2: error: 'people' was not declared in this scope
base.cc:12:9: error: expected ';' before 'p'
base.cc:21:10: error: 'mb' was not declared in this scope
base.cc:23:10: error: 'mb' was not declared in this scope
base.cc:25:10: error: 'mb' was not declared in this scope
base.cc:27:10: error: 'mb' was not declared in this scope
base.cc:30:10: error: 'fb' was not declared in this scope
base.cc:32:10: error: 'fb' was not declared in this scope
base.cc:34:10: error: 'fb' was not declared in this scope
base.cc:36:10: error: 'fb' was not declared in this scope
base.cc:39:2: error: 'p' was not declared in this scope
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2