so I’ve got this:
class SettingBase {
public:
virtual ~SettingBase() { }
};
template<typename T>
class Setting : private SettingBase {
friend class Section;
public:
std::string const &get_name() { return name; } // and my compiler
const char *get_name() { return name.c_str(); } // doesn't like this.
T const &get_value() throw() { return value; }
private:
Setting(std::string name, T value) : name(name), value(value) { }
Setting(const char *name, T value) : name(std::string(name)), value(value) { }
std::string name;
T value;
};
and then gcc says
config.cpp:74:17: error: ‘const char* Setting<T>::get_name()’ cannot be overloaded
config.cpp:73:24: error: with ‘const std::string& Setting<T>::get_name()’
Any particular reason for this?
Thanks,
Julian.
You cannot overload solely based on return type because the return type is not considered during overload resolution.
Two overloads must have different parameter types, different numbers of parameters, or (for member functions) different const-, volatile-, and reference-qualification.