【问题标题】:C2679 binary '=': no operator found which takes a right-hand operand of type 'point_t' (or there is no acceptable conversion)C2679 二进制“=”:未找到采用“point_t”类型右侧操作数的运算符(或没有可接受的转换)
【发布时间】:2018-04-22 09:49:34
【问题描述】:

我正在尝试做一种在 .csv 文件中写入向量和“严重性代码描述项目文件行抑制状态”的方法 错误 C2679 二进制“=”:未找到采用“point_t”类型的右手操作数(或没有可接受的转换)的运算符”不断弹出,我看到了许多与此类似的问题,但没有解决方案可以帮助我这……

方法:

result_en CLogger::Log(const vector<point_t>& pointsVector)

vector<point_t> tmp;
tmp = pointsVector;

if (this->binary == false)
{
    std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<point_t>(file, ";"));

    return res_ok;
}

我已经包含了 vector、cstdlib、iterator、fstream 没有任何作用。

【问题讨论】:

  • 那么point_t是什么?
  • point_t 支持复制分配吗?
  • 哦,对不起,我忘了添加这个...struct point_t { double x, y, z; };
  • Sergey 你能解释一下你在支持复制分配方面是什么意思吗?也许这就是问题
  • 除非point_t 具有支持std::ostream&amp; operator &lt;&lt;(std::ostream&amp;,point_t const&amp;) 的免费功能,否则这将不起作用。如果您没有其中之一,也许您应该提供一个?

标签: c++ vector methods iterator


【解决方案1】:

你需要这样声明的函数:

std::ostream& operator<<(std::ostream& s, const point_t& p)
{
     return s << '(' << p.x << ',' << p.y << ',' << p.z << ')';
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多