I am receiving this error invalid conversion from ‘const char*’ to ‘char*’ from this code:
// in account.h
struct account {
char* get_name ( ) const;
char name[MAX_NAME_SIZE+1];
};
//in account.cxx
char* account::get_name ( ) const
{
return name;
}
Can someone please help me?
The return type should be
const char*as well:It is because in a const member function,
thispointer becomes a const, as a result of which every member of the class becomes const, which meansnamewhich is declared aschar[N], becomesconst char[N]in a const member function.const char[N]can converts into onlyconst char*, hence you need to make the return typeconst char*.