If m is const , only const methods can be called on it. Perhaps you can change your method to
const char* Medicine::getName() const;
and use it as follows:
const char* n=m.getName();
Although you can use the std::string data element instead of the char array.
source share