Are you already cursing C++? I suspect what you meant to name your class is
"course"[
^], not
"curse"[
^] ;-)
That said,
friend
should be used very sparingly in C++! it is a keyword that is sometimes necessary for
strongly interdependend classes, such as container classes (e. g. std::vector) and their corresponding iterators.
For any other case, friend is a way of saying
Encapsulation[
^] is your enemy. But it isn't - and you should reallly learn how to work with it:
Enter the world of
accessors and mutators[
^]. Instead of calling every other class that may interact with your class a
friend
(something you can't even know when your application is a library used by a program you didn't write), provide a neat interface that lets others access your protected member variables in a controlled way:
class Course {
private:
char* name;
int mark;
public:
Course();
Course(const char* course_name, const int course_mark);
const char* get_name() const;
const int get_mark() const;
void set_name(const char* new_name);
void set_mark(const int new_mark);
};
The accessor and mutator functions will allow you to read and write member variables without accessing them directly. This will allow you to control access and verify changes within the class. For example, if your Course already holds a valid name and mark, you may not want to allow overwriting it. E. g. replace the two set functions above with a single one like that:
bool set(const char* course_name, const int new_mark) {
bool result = true;
if (name == nullptr) {
...
}
else if (strcmp(course_name, name) == 0) {
mark = new_mark;
}
else {
result = false;
}
return result;
}
Now you have restricted the way others can change your member variables without knowing who will ever use this class.
For the class Student it's similar: you should write accessors and mutators if you want others to read and write your member variables. Feel free not to provide these for every member variable, or maybe only provide accessors for reading.