草庐IT

Operator

全部标签

c++ - 辛>> "no operator matches these operands"

我一直在visualstudio2012控制台模式下处理一个C++项目,我一直在使用cin函数时遇到这个奇怪的持续性错误。在>>>下,我得到一条红线,程序告诉我没有运算符匹配这些操作数。我已经在单独的方法中初始化了所有数组元素。这是一个片段示例(实际代码包含更多变量):for(inti=0;i>allTaxiDetails[i].taxiRank;}allTaxiDetails是一个数组,数据类型为“taxiDetails”,结构如下:structtaxiDetails{stringtaxiDriverSurname;inttaxiID;inttaxiCoordinates;intnu

c++ - libstdc++ 中的 ostream operator<< 是线程敌对的吗?

ostream运算符(operator)使用num_put::put()用于数字格式化。我正在尝试遵循代码。我将链接到OSX文件,但类似的文件出现在我看过的其他一些系统上。在我看来num_put::put()电话num_put::do_put(),它调用num_put::_M_insert_float(),这calls__convert_from_v():http://www.opensource.apple.com/source/libstdcxx/libstdcxx-60/include/c++/4.2.1/bits/c++locale.hhttp://www.opensource

c++ - Visual C++ - 显式调用基本类型的转换运算符

我正在研究一个Foo类,它定义了一个隐式的operatorbool()。我使用Foo作为几个函数的返回类型,所以我可以获得有关已完成的操作的信息并调用Foo::operatorbool()来获取是否操作已成功执行。出于好奇,我还尝试在使用Foo时显式调用转换运算符:if(!func().operatorbool())//funcreturnedFoothrowstd::logic_error("operationwasnotsuccessful");效果很好。然后,我突然决定转储Foo类并使用简单的bool但我忘了删除.operatorbool()函数调用返回值。因此我发现了一组Vis

c++ - 为什么不使用私有(private)基地的类型转换运营商?

在此代码中,分配给b1有效,但它不允许分配给b2(有或没有静态转换)。我实际上是在尝试解决相反的问题,公共(public)继承但不隐式转换为基础。但是,似乎从未使用过cast运算符。这是为什么?structB{};structD1:privateB{operatorB&(){return*this;}B&getB(){return*this;}};structD2:publicB{explicitoperatorB&(){return*this;}};structD3:publicB{operatorB&()=delete;};voidfunB(B&b){}intmain(){D1d1

运算符的 C++ 链接 << for std::cout like usage

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:std::endlisofunknowntypewhenoverloadingoperatorOperatoroverloading我目前正在编写一个记录器类,但是operator方法导致编译器错误。这是该类的最小化版本,位于文件“logger.h”中:#includeclassLogger{public:Logger():m_file(std::cout){}templateLogger&operator它包含在我的main.cpp中,当我输出字符串文字时它可以完美地工作:log但是,下面的代码不会编译。#

c++ - 绑定(bind) lambda 的速度(通过 std::function)与仿函数结构的 operator()

autolam=[](inta,intb,intc){returna在版本一中,我们std::vector>lamvals;//getparametersandforeachlamvals.emplace_back(std::bind(lam,a,std::placeholders::_1,b));替代方案是std::vectorlamvals;//getparametersandforeachlamvals.emplace_back(functor{a,b});在这两种情况下我们都有一个简单的迭代returnstd::any_of(lamvals.cbegin(),lamvals.c

c++ - 将流运算符 >> 评估为 bool 值

以下代码在VisualStudio2008中编译但在VisualStudio2013及更高版本中失败。std::stringstr("foo");std::stringstreamss(str);floatf=0;if((ss>>f)==false)std::cout错误信息是errorC2678:binary'==':nooperatorfoundwhichtakesaleft-handoperandoftype'std::basic_istream>'(orthereisnoacceptableconversion)并通过如下更改成功修复:if(!(ss>>f))std::cout

c++ - 重载运算符 '[]' 的使用与模板转换运算符不明确

以下代码在gcc7.3.0中编译良好,但在clang6.0.0中无法编译。#includestructX{X():x(10){}intoperator[](std::stringstr){returnx+str[0];}templateoperatorT(){returnx;}//(1)failsonlyinclang//operatorint(){returnx;}//(2)failsbothingccandclangprivate:intx;};intmain(){Xx;inty=20;intz=int(x);returnx["abc"];}我使用命令clang++1.cpp-st

c++ - 重载全局类型转换运算符

为了测试和显示我的库中某些函数的结果,我创建了一组方便的函数。我有一个execute看起来像的功能:templatestd::stringexecute(conststd::string&func_name,R(*func_ptr)(constI&),constI&func_input);它调用该函数,并在我可以发送到std::cout的格式化字符串中显示结果和参数。.问题是我的一些函数不返回convertible-to-string结果。我以为我可以简单地重载全局::operatorstd::string像这样:templateoperatorstd::string(conststd

c++ - boost shared_ptr : difference between operator= and reset?

下面两段代码有区别吗?它们中的任何一个比另一个更可取吗?运算符=boost::shared_ptrfoo;//foo.ptrshouldbeNULLfoo=boost::shared_ptr(newBlah());//Involvescreationandcopyofashared_ptr?重置boost::shared_ptrfoo;//foo.ptrshouldbeNULLfoo.reset(newBlah());//foo.ptrshouldpointnowtoanewBlahobject注意:我需要定义shared_ptr然后将其设置在不同的行中,因为我在一段代码中使用它,例如