I need help with this code ect...

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)

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
// this is a practice
#include <iostream>

using namespace std;

class Student;         // forward declaration used so we can use Student class
class Teacher
{
	friend void registration(Teacher& t, Student& s);

public:
	void assignGrades();
protected:
	int noStudents;
	Student *pList[100];
};

class Student
{
	friend void 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???

}
Topic archived. No new replies allowed.