0

我正在实现以下功能:

bool DenStream::_try_merge(const double sample,
                           const double weight,
                           const std::optional<MicroCluster>& micro_cluster) const {
    if (micro_cluster) {
        MicroCluster micro_cluster_copy(*micro_cluster);
        micro_cluster_copy.insert_sample(sample, weight);
        if (micro_cluster_copy.get_radius() <= this->eps) {
            micro_cluster.insert_sample(sample, weight); // THIS DOES NOT WORK
            return true;
        }
    }
    return false;
};

编译器说错误: 'const class std::optional' has no member named 'insert_sample'

我了解该错误,但我无法找到有效的解决方案。如果我写

*micro_cluster.insert_sample(sample, weight);

编译器说错误: 'const class std::optional' has no member named 'insert_sample'。我也尝试过 emplace() 和 value()。

如果有人可以帮助我,我将不胜感激。

好的,现在它可以工作了。正如评论中所建议的,我改为

micro_cluster->insert_sample(sample, weight);

并且界面必须是

bool DenStream::_try_merge(const double sample,
                           const double weight,
                           std::optional<MicroCluster>& micro_cluster)

谢谢!

4

0 回答 0