Ok so I am currently reading my c++ book and wanted to test one of the code examples, its pretty much on the topic on "Giving non-member functions access to protected members" and so far I copied everything down but I can't seem to find out how to access the function from main since everything goes through main.
Do I need to declare the registration function in main to get to it? because i tried that but then it sets Teacher referencing t and Student referencing s ect.
If anyone could help that be awesome, I am a beginner of course and trying to learn all I can before I step into using API's for game programming. I just don't want to end up giving up on this when I might have to use it down the road. btw I hate protected members... (Book is C++ for dummies - only book I actually understand)
// this is a practice
#include <iostream>
usingnamespace std;
class Student; // forward declaration used so we can use Student class
class Teacher
{
friendvoid registration(Teacher& t, Student& s);
public:
void assignGrades();
protected:
int noStudents;
Student *pList[100];
};
class Student
{
friendvoid registration(Teacher& t, Student& s);
public:
// put public members here if needed
protected:
Teacher *pT;
int semesterHours;
float gpa;
};
void registration(Teacher& t, Student& s)
{
// initialize student objects
s.semesterHours = 0;
s.gpa = 0;
// if there is room on list
if (t.noStudents < 100)
{
// add it onto the end of the list
t.pList[t.noStudents] = &s;
t.noStudents++;
}
}
int main(int nNumberofArgs, char*pszArgs[])
{
// clueless on what to put here???
}