找出解码器重写里的 bug

来自 虚函数
C++23 进阶 4分钟 找出 1处问题

找出为什么通过 Decoder& 调用时没有使用 JsonDecoder。

C++
#include <string>
#include <string_view>

class Decoder {
public:
    virtual std::string decode(std::string_view input) const {
        return std::string(input);
    }
    virtual ~Decoder() = default;
};

class JsonDecoder final : public Decoder {
public:
    std::string decode(std::string_view input) {
        return "json:" + std::string(input);
    }
};
在试验场中打开
报告错误