草庐IT

operation_type

全部标签

c++ - C++ 代码错误 "expected constructor, destructor, or type conversion before ‘(’ token ”和 "no matching function for call to ..."

真正尝试解决错误,仔细检查所有内容。请帮忙。c++新手,请多关照。头文件(.h)#ifndefGUARD_Optimized_quick_sort_h#defineGUARD_Optimized_quick_sort_h#include#include#includeusingnamespacestd;templateclassoptimized_quick_sort{public:optimized_quick_sort(vectorarray){this->array=array;}optimized_quick_sort(listarray){vectortemp(array.b

c++ - "No match for operator="试图在 C++ 中遍历映射

我正在尝试遍历定义如下的map:std::map>ridx_;现在我尝试在以下重载运算符的友元函数中遍历ridx_(它是一个类的私有(private)成员)std::ostream&operator>::iteratorit;//Thefollowingisline34for(it=m.ridx_.begin();it!=m.ridx_.end();it++)osfirst但是g++错误输出:SMatrix.cpp:34:error:nomatchfor'operator='in'it=m->SMatrix::ridx_.std::map::beginwith_Key=unsigned

c++ - std::map 的 int 类型比较的 operator< 重载? (我希望它按降序排序..)

我遇到了一个问题,我想定义一个map,它在内部按第一个的降序排序。如果第一个不是主要类型,比如它是一个类,我可以在该类中重载“非常感谢!! 最佳答案 添加比较器:#includemap>m;默认为less. 关于c++-std::map的int类型比较的operator https://stackoverflow.com/questions/8659744/

c++ - operator new 已经有一个主体

我正在尝试将参数作为全局参数来实现operatornew。如果没有args的new重载没有问题,但是在尝试编译时出现以下错误inlinevoid*operatornew(size_t,void*p){//...returnp;}c:\bjarne_exercise_6.cpp(14):errorC2084:function'void*operatornew(size_t,void*)throw()'alreadyhasabodyc:\programfiles\microsoftvisualstudio10.0\vc\include\new(55):seepreviousdefiniti

c++ - 提升精神 : how to convert basic types?

假设我有一个std::string属性,但为了便于解析,我想使用qi::int_或qi::double_.是否有一种简单的方法可以将转换作为语义操作进行?我试过这样的:std::stringstreamss;my_int_as_str=qi::int_[ref(ss)但这甚至无法编译。编辑-尝试使用下面sehe的回答#include#include#include#includenamespaceqi=boost::spirit::qi;namespacephx=boost::phoenix;intmain(intargc,char*argv[]){std::stringtest="1

c++ - '*(<type> *) &x' 和 'x' 有什么区别?

有什么区别inti=123;intk;k=*(int*)&i;cout和inti=123;intk;k=i;cout它们都给出相同的输出,但有什么不同吗?(我在快速平方根反函数的Quake3代码中找到了第一个片段) 最佳答案 第三季度:floatQ_rsqrt(floatnumber){longi;floatx2,y;constfloatthreehalfs=1.5F;x2=number*0.5F;y=number;i=*(long*)&y;//evilfloatingpointbitlevelhackingi=0x5f3759df

c++ - 从 std::tuple<some_types...> 开始创建子元组

让我们假设一个std::tuple给出。我想创建一个新的std::tuple其类型是在[0,sizeof...(some_types)-2]中索引的类型.例如,假设起始元组是std::tuple.我想获得一个定义为std::tuple的子元组.我对可变参数模板很陌生。作为第一步,我尝试写一个struct负责存放不同类型的原件std::tuple目的是创建一个新的同类元组(如std::tuplenew_tuple)。templatestructtype_list;templatestructtype_list:publictype_list{typedefTtype;};template

c++ - 为什么 C++ STL 容器使用 "less than"operator< 而不是 "equal equal"operator== 作为比较器?

在std::map的自定义类中实现比较运算符时,我遇到了这个问题,但看不到任何被问到的地方。除了上述问题,也有兴趣简要了解,如何operator适用于std::map.问题来源:structAddress{longm_IPv4Address;boolisTCP;booloperator 最佳答案 std::map需要能够排序。默认情况下使用std::less,对于非指针使用1。使用您对用户的要求最少的规则,它从综合“等价”当它需要它时(!(a表示a和b是等价的,即两者都不小于另一个)。这使得编写用作map的关键组件的类变得更加容易,

c++ - operator bool() 转换为 std::string 并与 operator std::string() 冲突

在类中声明operatorstd::string时,operatorbool()怎么会导致错误,而且它本身还充当到string的隐式转换?#include#includeusingnamespacestd;classTest{public:operatorstd::string(){cout 最佳答案 您面临的问题(除了operatorstd::string()返回bool之外)是隐式转换在您需要和不需要时触发。当编译器看到s=t时,它会识别以下潜在的std::operator=匹配项://usingstd::stringforco

c++ - 将 operator== 重载为带有模板参数的自由函数的语法是什么?

我有一组多态类,例如:classApple{};classRed:publicApple{};classGreen:publicApple{};以及比较它们的自由函数:booloperator==(constApple&,constApple&);booloperator我正在设计一个可复制的包装器类,它将允许我使用类Red和Green作为STL映射中的键,同时保留它们的多态行为。templateclassCopy{public:Copy(constCat&inCat):type(inCat.clone()){}~Copy(){deletetype;}Cat*operator->(){