Hi, I have a simple class Name:
class Name
{ private:
char nameStr[30];
public:
Name(const char * = "");
char * getName() const;
void print() const;
};
I am having two problems, which are just a bit difficult for me wrap my head around. The constructor is supposed to take an argument of const char * and copy that into the nameStr array. However, this is what I have tried and is not working:
Name::Name(const char * setName)
{
&nameStr = setName;
}
It gives me the error "invalid lvalue in assignment". If I remove the reference in front of nameStr, it still errors, saying "incompatible types in assignment of 'const char*' to 'char[30]'". Not quite sure what I'm missing.
The other problem is the accessor method:
char * Name::getName() const
{
return &nameStr[0];
}
I have the same problem, it errors "invalid conversion from 'const char*' to char*'" and I can't for the life of me figure out how to make it return a pointer to a const char... I've been searching to avail. Found plenty of info on const, but can't quite figure how to apply it to my situation. Any help would be greatly appreciated!