Private public errors

closed account (ybq5Djzh)
I have the following class

class student
{
private:
char name[50];
public:
student *left;
student *right;
void setName (char nm[])
{
strcpy (name, nm);
}
void getName (char nm[])
{
strcpy (nm, name);
}
student (char key[])
{
strcpy (name, key);
left = NULL;
right = NULL;
}
};

This is saved as "Student_Class.h"

Now, in my main program I have

#include<iostream>
#include<cstdio>
#include<cstring>
#include "Student_Class.h"

void treeInsert (student *& root, char key[])
{
char item[50];
root -> getName (item);
if (root == NULL)
{
root = new student (key);
}
else if (key < item)
{
treeInsert (root -> left, key);
}
else if (key > item)
{
treeInsert (root -> right, key);
}
}

int main ()
{
blah blah
}

It says i can't use root -> getName () because student::name[50] is private. How do I resolve this? I cant make it public because there are many other variable for which i have to do this.
You can use a different return type
1
2
3
4
5
6
7

char getName (char nm[]) {

  return name;

}
Topic archived. No new replies allowed.