Reputation: 482
char* n=m.getName();
I get the following error Invalid arguments ' Candidates are: char * getName() '
for the above instruction.What am I missing?
char* Medicine::getName()
{
return this->name;
}
name
is of declared as char name[50];
andm
is const Medicine& m
Upvotes: 4
Views: 891
Reputation: 2464
Please note that if the member variable is const, only const member function can access this. Same for static, i.e if the member variable is static only a static member can access that.
Upvotes: 0
Reputation: 227618
If m
is const
, then only const
methods can be called on it. Maybe you can change your method to
const char* Medicine::getName() const;
and use it like this:
const char* n=m.getName();
Although you might consider using an std::string
data member instead of an array of char
.
Upvotes: 9