C机械手未被执行

C机械手未被执行,第1张

概述好吧,我想知道为什么endd似乎没有执行(尽管它在编译时不会产生任何错误). struct dxfDato{ dxfDato(int c, string v = 0, int t = 0) { codigo = c; valor = v; tipo = t; } dxfDato() { } int tipo; int codigo; string val 好吧,我想知道为什么endd似乎没有执行(尽管它在编译时不会产生任何错误).

struct dxfDato{    dxfDato(int c,string v = 0,int t = 0) { codigo = c; valor = v; tipo = t; }    dxfDato() { }    int tipo;    int codigo;    string valor;};class dxfItem{private:    std::ostringstream ss;    typedef std::ostream& (*manip)(std::ostream&);public:    int clase;    string valor;    vector<dxfDato> datos;    vector<dxfItem> hijos;    template <typename T>    dxfItem& operator<<(const T& x)    {        ss << x;        return *this;    }    dxfItem& operator<<(manip x) // to store std manipulators    {        ss << x;        return *this;    }    static dxfItem& endd(dxfItem& i) // specific manipulator 'endd'    {        dxfDato dd;        dd.valor = i.ss.str();        i.datos.push_back(dd);        std::cout << "endd found!" << endl;        return i;    }};/* blah blah blah */dxfItem header;header    << 9 << endl << "$ACADVER" << endl << 1 << endl << "AC1500" << endl    << dxfItem::endd // this apparently doesn't execute anything    << "other data" << endl;

这是我在尝试开发某些东西时发现的最后一个问题.最后一件事暴露在这里:C++ Operator overloading example

谢谢你们!

解决方法 您已经将类型 *** 作定义为通过引用获取std :: ostream并通过引用返回std :: ostream的函数,但是您已定义endd以获取dxfItem并返回dxfItem并且dxfItem不是从std派生的:: ostream的.

由于这种类型不匹配,编译器正在生成对运算符的调用<<模板,而不是 *** 纵过载.
此外,你的 *** 作重载需要实际调用传递给它的 *** 纵器函数:

dxfItem& operator<<(manip x){   x(ss);   return *this;}
总结

以上是内存溢出为你收集整理的C机械手未被执行全部内容,希望文章能够帮你解决C机械手未被执行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1212723.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存