1

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Because return type is not a criteria for function overloading.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.