Review a generated report interface

from Virtual functions
C++23 advanced 6 min 4 issues to find

Review this generated hierarchy against the requested contract.

Return owned reports through Report, render them polymorphically, destroy them safely, and expose report text without an inspection copy.

C++
#include <memory>
#include <string>
#include <utility>

class Report {
public:
    explicit Report(std::string text) : text_(std::move(text)) {}
    virtual std::string render() const { return text_; }
    std::string text() const { return text_; }
    ~Report() = default;
protected:
    std::string text_;
};

class HtmlReport final : public Report {
public:
    using Report::Report;
    std::string render() { return "<p>" + text_ + "</p>"; }
};

std::unique_ptr<Report> make_report() {
    return std::make_unique<HtmlReport>("ready");
}

generated code is illustrative, not from any one model

Open in playground
Report an error