0

trying to make this college assignment with multiple inheritance. Here is the Student class, that is supposed to use MI:

#include "Person.h"
#include "Studying.h"
#include "StudentRoll.h"

class Student : public Person, public Studying {
    private:
    int mathScore;
public:
   Student(string n,int b,int i,int c,double a):Person(n,b),Studying(i,c,a){}
    string toString();
    friend class StudentRoll;
};

And here are its ancestors:

#include <string>

using namespace std;

class Person {
private:
    string name;
    int birthYear;
public:
    Person() :name(""), birthYear(1900){}
    Person(string n, int y);
    void setBirthYear(int y);
    string toString();
};


using namespace std;

class Studying {
private:
    int id;
    int course;
    double average;
public:
   Studying():id(0),course(1),average(3.0){}
   Studying(int i, int c, double a):id(i),course(c),average(a){}
   void setCourse(int c);
   string toString();
   };

I get some weird errors with the following class

#pragma once
#include "Student.h"
#include <vector>
#include <iostream>

using  namespace std;

class StudentRoll {
private:
    vector<Student> students;
public:
   void push(Student s);
   void pop();
   void show();

};

And here are the errors:

Severity Code Description Project File Line Error C2923 'std::vector': 'Student' is not a valid template type argument for parameter '_Ty' lab3 i:\onedrive\uni\oop\lab3\lab3\studentroll.h 10

Severity Code Description Project File Line Error C3867 'std::vector>::size': non-standard syntax; use '&' to create a pointer to member lab3 i:\onedrive\uni\oop\lab3\lab3\studentroll.cpp 17

Severity Code Description Project File Line Error C2065 'Student': undeclared identifier lab3 i:\onedrive\uni\oop\lab3\lab3\studentroll.h 10

Severity Code Description Project File Line Error C2248 'Student::mathScore': cannot access private member declared in class 'Student' lab3 i:\onedrive\uni\oop\lab3\lab3\studentroll.cpp 22

Severity Code Description Project File Line Error C2061 syntax error: identifier 'Student' lab3 i:\onedrive\uni\oop\lab3\lab3\studentroll.h 12

I can include cpps in case they are necessary. Please, help

small-j
  • 309
  • 1
  • 4
  • 12
  • 4
    You have circular dependency between `Student.h` and `StudentRoll.h`. See http://stackoverflow.com/questions/625799/resolve-circular-dependencies-in-c. – R Sahu Sep 22 '15 at 19:56
  • 5
    Note, you should never put `using namespace std;` in a header. – James Adkison Sep 22 '15 at 19:57
  • 2
    Some tips: start by removing all `using namespace std;`, read about why [here](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). You can also read about include guards [here](http://stackoverflow.com/questions/8020113/c-include-guards). – sweerpotato Sep 22 '15 at 19:58
  • 1
    removing the `#include "StudentRoll.h"` from `Student.h` should relieve a lot. – Ryan Haining Sep 22 '15 at 20:07
  • Note that the "toString() is ambiguous, that you might want to make one of the implementations virtual. – macetw Sep 22 '15 at 20:17
  • You might also choose to make student::mathScore a protected member, rather both private + friend. – macetw Sep 22 '15 at 20:18
  • Thank you, removing the circular dependency helped a lot. Need to mark the question as answered – small-j Sep 22 '15 at 20:19

1 Answers1

0

Remove the #include "StudentRoll.h" from Student.h, which is a circular dependency.

Community
  • 1
  • 1
sweerpotato
  • 470
  • 2
  • 11
  • 22