Deriving error along with class/struct/union error

Hello I have an error of the derived class(IDscore.h) not having getscore as a member even though it should be since it is part of the testscore.h which is what idscore.h is derived from this error occurs in the scoretesting.cpp towards the end at getscore()

the other error i have is the ".what" imust have a class/struct/ union which i dont understand.

The other errors i get are in the TestScore.h where the TestScore and TestError are both giving me a class type redefinistion error when I already tried adding #indef and #endif but thAt didnt help.

I have edited this program without adding a derived class and it works fine so i would have assumed that adding a derived class would have been no difference but it is.

Here are the files i have and I can only change the Scoretesting,IDscore.h , idscore.cpp Thanks for any help



TestScore Header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
#include<string>
using std::string;
#include<iostream>
using namespace std;

#include<stdexcept>
using std::runtime_error;

class TestError : public runtime_error
{
  public:
    TestError(const string& msg):runtime_error(msg){}
};

class TestScore
{
  public:
    TestScore(const char *in_name, int in_score);
    TestScore(string in_name, int in_score);
    string getName(void);
    int getScore(void);

  private:
    string studentName;
    int studentScore;
};



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


#include"TestScore.h"

#include<string>
#include<iostream>
using namespace std;


class IDScore:public TestScore
{
  public:
    IDScore(const char *in_name, int in_score, const int in_stuID);
    IDScore(string in_name, int in_score,int in_stuID);
   int getID(void);

  private:
 
	int stuID;
}; 




IDSCore cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include"IDScore.h"
#include"TestScore.h"

#include<iostream>


IDScore::IDScore(const char *in_name, int in_score, const int in_stuID) : TestScore (in_name,  in_score)
{
  if(in_stuID > 0) 
  {
    stuID=in_stuID;
  } 
  else
  {
    throw TestError("ID is less than 1");
  }

      if(in_score > 0)
{

	in_score=getScore();
  }
  else {
    throw TestError("Negative grade");
  }
}


IDScore::IDScore(string in_name, int in_score, int in_stuID): TestScore(in_name, in_score)
  
{
  if(in_stuID > 0)
  {
    stuID=in_stuID;
  }
  else
  {
    throw TestError("ID is less than 1");
  }
    if(in_score > 0)
	{
    in_score=getScore();
  }
  else {
    throw TestError("Negative grade");
  }
}

string TestScore::getName(void)
{
  return studentName;
}


int IDScore::getID(void)
{
  return stuID;
}

int TestScore::getScore(void)
{
	return studentScore;
}



ScoreTesting cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<iomanip>
using std::setfill;
using std::setw;
using std::setprecision;
using std::left;

#include<string>
using std::string;

#include"IDScore.h"
#include"TestScore.h"



int main()
{
  int count(0);
  bool valid;

  while(count < 1) {
    cout << "How many students took the exam? ";

    while(!(cin >> count)) {
      cin.clear();
      cin.ignore();
    }
  }

  IDScore **roll=new IDScore*[count];
  for(int i=0;i<count;i++) {
    roll[i]=0;
  }

  int newScore;
  int newStuID;
  string newStudent;

  for(int i=0; i< count; i++) {
    valid=false;
    while(! valid) {
      valid=true;
      cout << "Enter student's name, ID number and score: ";
	  cin >> newStudent;
	  cin >> newStuID;
      while(!(cin >> newScore)) 
	  {
        cin.clear();
        cin.ignore();
      }
      try {
        roll[i]=new IDScore(newStudent,newStuID,newScore);
      }
      catch(TestError& e)
	  {
        valid=false;
        cout << e.what() << endl;
        if(roll[i]!=0) {
          delete roll[i];
          roll[i] = 0;
        }
      }
    }
  }

  cout << endl;

  int total(0);
  for(int i=0; i< count; i++) 
  {
    total+=roll[i]->getScore();
	cout << left << setw(18) << roll[i]->getID() << ": " << 
      roll[i]->getScore() << endl;
  }

  cout << setfill('_') << setw(45) << "\n" << endl;
  cout << setw(1) << "Test Average is : " << setprecision(2) << 
    (float)total/count << endl;

  return 0;
}


Always copy the exact errors that you get and paste them here.

fyi it runs fine here aside from your function call parameter order not matching the function definition:

How many students took the exam? 3
Enter student's name, ID number and score: John 1 90
Enter student's name, ID number and score: Jane 2 100
Enter student's name, ID number and score: Juan 42 95

90 : 1
100 : 2
95 : 42

____________________________________________
Test Average is : 15


If you are using an IDE, try cleaning your project.
Here are the errors.. i cleaned and also rebuild but i still get these errors...
Also which function call parameters are you referring to when you say they are not matching?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Error	4	error C2228: left of '.what' must have class/struct/union	h:\personal\visual studio 2012\projects\program13\program13\scoretesting.cpp	67	1	Program13


Error	5	error C2039: 'getScore' : is not a member of 'IDScore'	h:\personal\visual studio 2012\projects\program13\program13\scoretesting.cpp	81	1	Program13


Error	6	error C2039: 'getScore' : is not a member of 'IDScore'	h:\personal\visual studio 2012\projects\program13\program13\scoretesting.cpp	83	1	Program13


Error	3	error C2027: use of undefined type 'TestError'	h:\personal\visual studio 2012\projects\program13\program13\scoretesting.cpp	67	1	Program13


Error	2	error C2011: 'TestScore' : 'class' type redefinition	h:\personal\visual studio 2012\projects\program13\program13\testscore.h	26	1	Program13


Error	1	error C2011: 'TestError' : 'class' type redefinition	h:\personal\visual studio 2012\projects\program13\program13\testscore.h	19	1	Program13
error C2011: 'TestScore' : 'class' type redefinition


Do you have include guards in your header files?
Topic archived. No new replies allowed.