I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");
but since name is private it is not possible... is there any way to do this??
Thanks,
1 2 3 4 5 6 7 8 9 10 11 12 13
// In Manager.h
#include"Student.h"
class Manager
{
staticconstunsignedint max = 10000;
Student Students[max];
public:
bool b_running;
Manager();
bool AddNewStudent();
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// In Student.h
#include "Name.h"
class Student
{
Name name;
public:
Student();
};
@devonrevenge
I see your point and agree with it: this is not a way you should assign c-strings
@questionmark
You probably want ot get rid of Name class and instead give student private name string providing SetName method in public interface.
You can make Manager a friend of Student, but it is not recomended.
Or you can provide Student with public setName method which will call name's method.