简体   繁体   中英

Call of Overloaded Functions is Ambiguous

I'm getting the error call of overloaded function is ambiguous and I understand it's because the compiler can't differentiate between them, but is there a way to work around this while maintaining the same parameters? I have to use the declarations I've provided below and it's confusing me as to how I can use them both if I met with this error every time.

I've shortened my code to show the constructors that are posing the issue.

ErrorMessage.h

class ErrorMessage {
        char* message_; //pointer that holds the address of the message stored in current object
    public:
        ErrorMessage();
        explicit ErrorMessage(const char* errorMessage = nullptr); //receive address of a C-style nullterminate string holding an error message
}

ErrorMessage.cpp

namespace sict {

ErrorMessage::ErrorMessage() {
    message_ = nullptr;
}

ErrorMessage::ErrorMessage(const char* errorMessage) {
    if(errorMessage == nullptr) {
        message_ = nullptr;
    }
    else {
        message(errorMessage);
    }
    const char* ErrorMessage::message() const {
        return message_;
    }
}

Just remove the constructor which takes no parameters. The second constructor already does everything the first constructor does.

If it receives a nullptr, it tests it and sets the local variable, if not it continues with its logic. The first constructor is completely superfluous.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM