问题
I am implementing the following function:
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;
};
The compiler says error: 'const class std::optional' has no member named 'insert_sample'.
I understand the error, but I have not been able to find a solution that works. If I write
*micro_cluster.insert_sample(sample, weight);
the compiler says error: 'const class std::optional' has no member named 'insert_sample'. I have also tried with emplace() and value().
I would appreciate if anyone can help me.
Okay, now it works. As suggested in the comments, I changed to
micro_cluster->insert_sample(sample, weight);
and the interface has to be
bool DenStream::_try_merge(const double sample,
const double weight,
std::optional<MicroCluster>& micro_cluster)
Thanks!
来源:https://stackoverflow.com/questions/61096479/stdoptionalt-call-by-reference