Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid arguments in classes

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

like image 535
Matt Avatar asked Jan 14 '23 10:01

Matt


1 Answers

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.

like image 121
juanchopanza Avatar answered Jan 23 '23 02:01

juanchopanza