本文介绍了我想避免声明一个函数!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在解析返回语句的问题,以返回 函数(我认为)。点击此处: 模板< typename T> A类{}; 模板< typename T> class maker_of_A { public: A< T>& make_A(){return A< T>();}; }; 模板类maker_of_A< float> ;; 这个例子给出了错误: typename.cc:在成员函数`A< T>& maker_of_A< T> :: make_A()[有T = 浮动]'': typename.cc:15:实例化自这里 typename.cc:11:无法将`{}''转换为'A< float>&'' 我只想返回对匿名(临时)A< T> 对象的引用。我可以在不创建明确的临时对象的情况下这样做吗? KCC做了我想要的而不抱怨,所以我从来没有想过 之前......(我知道这个例子没有意义,它适用于 显示我正在拥有的问题。) 谢谢, / PatrikHi,I''m having a problem with a return statement being parsed to return afunction (I think). Check here:template <typename T> class A {};template <typename T> class maker_of_A {public:A<T>& make_A() {return A<T>();};};template class maker_of_A<float>;This example gives the error:typename.cc: In member function `A<T>& maker_of_A<T>::make_A() [with T=float]'':typename.cc:15: instantiated from heretypename.cc:11: could not convert `{}'' to `A<float>&''I just want to return a reference to an anonymous (temporary) A<T>object. Can I do this without creating an explicit temporary object?KCC did what I wanted without complaining, so I''ve never thought aboutthis before... (I know the example doesn''t make sense, it''s adapted toshow the issue I''m having.)Thanks,/Patrik推荐答案 大概是没有。 - 答:因为它弄乱了人们通常阅读文字的顺序。 问:为什么这么糟糕? A:热门发布。 问:什么是最烦人的事情usenet和电子邮件?Presumably it didn''t.--A: Because it messes up the order in which people normally read text.Q: Why is it such a bad thing?A: Top-posting.Q: What is the most annoying thing on usenet and in e-mail? 这篇关于我想避免声明一个函数!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 15:50
查看更多