4
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

Matt
  • 484
  • 5
  • 15

2 Answers2

9

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.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
0

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.

Naseef Chowdhury
  • 2,357
  • 3
  • 28
  • 52