compilation error

Hello! Can anyone explain me why if I make the function get_fName a const function, it returns _fName only with the casting (char*)? Without casting, it not compiles.
On the other hand, if I remove the const, it returns _fName also without casting?

1
2
3
4
5
6
7
8
9
10
11
  class Student
{
	int _id;
	char _fName [20];
        char* get_fName() const;
}
// implementation
  char* Student::get_fName () const
{
	return (char*)_fName;
}
Last edited on
don't ask the same question multiple times.
http://www.cplusplus.com/forum/beginner/168611/
That question was not formulated as well.
This is another question:

1
2
3
4
5
6
7
8
9
10
11
class Student
{
    int _id;
    char _fName [20];
    char* get_fName() const;
}
// implementation
char* Student::get_fName () const
{
    return _fName;
}


Why doesn't it compile???
The compiler says that _fName is inaccible
Last edited on
Topic archived. No new replies allowed.