Receiving various errors, need help!

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
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;


const int MAX_CHAR = 100;

class Student
{
public:
	Student::Student(const char initId[], float initGpa){
		strcpy(id, initID);
		gpa = initGpa;
	}

	bool Student::isLessThanByGpa(const Student& aStudent){
		if (gpa < aStudent.getGpa()){
			return true;
		}

		else{
			return false;
		}
	}

	bool Student::isLessThanByID(const Student& aStudent){
		if (strcmp(id, aStudent.getId()) > 0){
			return true;
		}
		else {
			return false;
		}
	}

	char getId(){
		return id;
	}

	float getGpa(){
		return gpa;
	}

private:

	char id[MAX_CHAR];
	float gpa;
};



/*Errors:
Error 1 error C2065: 'initID' : undeclared identifier
Error 2 error C2662: 'float Student::getGpa(void)' : cannot convert 'this' pointer from 'const Student' to 'Student &'
Error 3 error C2662: 'char Student::getId(void)' : cannot convert 'this' pointer from 'const Student' to 'Student &'
Error 4 error C2660: 'strcmp' : function does not take 1 arguments
Error 5 error C2440: 'return' : cannot convert from 'char [100]' to 'char'
6 IntelliSense: identifier "initID" is undefined
7 IntelliSense: the object has type qualifiers that are not compatible with the member function
object type is: const Student
8 IntelliSense: the object has type qualifiers that are not compatible with the member function
object type is: const Student
9 IntelliSense: return value type does not match the function type

*/
Last edited on
report in code tags please.
and tell us the errors too.
Hello,

What do you mean by "report in code tags"?


Thanks!
Highlight your code and press the <> button (or use [ code ] and [ /code ] without the spaces).
done and done, thanks shadowmouse
One thing I noticed immediately: you haven't defined anything called initID anywhere in your code.


Error 1 error C2065: 'initID' : undeclared identifier
C++ is case-sensitive, so initId != initID
Error 2 error C2662: 'float Student::getGpa(void)' : cannot convert 'this' pointer from 'const Student' to 'Student &'
function getGpa should be const, so change line 41 with float getGpa() const {
Error 3 error C2662: 'char Student::getId(void)' : cannot convert 'this' pointer from 'const Student' to 'Student &'
function getId should be const and the return type should be const char*, so change line 37 with const char* getId() const {
Error 4 error C2660: 'strcmp' : function does not take 1 arguments
I don't get this error
Error 5 error C2440: 'return' : cannot convert from 'char [100]' to 'char'
see Error 3

Anyway, I suggest you to #include <string> and use std::string instead of char arrays, strcpy and strcmp: it should be simpler to write and less error-prone.
Topic archived. No new replies allowed.