1
所以我有這樣的:不能超載的std :: string常量和函數爲const char *
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;
};
然後GCC說
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()’
有什麼特別的原因?
謝謝,
朱利安。