OK, we are being introduced to classes in my C++ class.
Here are my .h files:
Code:
// "str.h" file
class Str { //create class 'str'
char s[32]; //define array of 32 characters
public:
Str (char *p=""); //ctor (default)
int operator<(Str &str); //operator
friend istream & operator>>(istream &in, Str &str);
friend ostream & operator<<(ostream &out, Str &str);
};
#endif
// "student.h" file
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream.h>
#include "str.h"
class student{
Str name;
int grade;
public:
student(char *n="", int g=0);
friend istream &operator >> (istream &in, student &student);
friend ostream &operator << (ostream &out, student &student);
};
#endif
Which looks ok.....
My main .cpp file returns errors, I am posting just one function for brevity:
Code:
void Sortbygrade (student s, int count)
{
for (int i=0; i< count-1; i++)
for (int j=0; j<count-1; j++)
if (s[j+1].grade > s[j].grade) //error here
{
student n;
n=s[j]; //error here
s[j]=s[j+1]; //error here
s[j+1]=n; //error here
};
}
My errors are as follows:
C:\Cpp1.cpp(54) : error C2676: binary '[' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
Now, where am I going wrong on the operator? I am sorting a list of students that will be read from a file.