草庐IT

MAKE_ENUM_OPERATOR_TYPESAFE

全部标签

c++ - 无法使用 C++ stdlib 系统调用运行 make

我在C++中得到了以下代码if(should_run_make){std::stringmake="make-C";make.append(outdir);std::cout报告如下:Makecmdismake-C/home/hamiltont/temp/make:Enteringdirectory/home/hamiltont/temp'make:***Notargets.Stop.make:Leavingdirectory/home/hamiltont/temp'但是,以多种方式手动执行此操作效果很好,例如[hamiltont@4generator]$make-C/home/ham

c++ - 使用转换的 operator+ 的模糊重载

我得到了一个转换konw->int,double->konw的类:classkonw{doublere,im;public:konw():re(0.0),im(0.0){}konw(doubler,doublei=0.0):re(r),im(i){}operatorint(){returnre;}konwoperator+(konwa){konwwynik;wynik.re=re+a.re;wynik.im=im+a.im;returnwynik;}};主要是我使用重载的operator+测试这些转换konwzesp(3.1,0.6);intssuma=zesp+6;编译器在处理最后一

c++ - 错误 : no instance of overloaded function "std::make_shared" matches the argument list

查看ApreviousstackQuestionstd:make_sharedvsstd::shared_ptr,我试图在一个uni项目中实现它。这是之前的“问题”:Ican'tthinkofanysituationwherestd::shared_ptrobj(newObject("foo",1));wouldbepreferredtoautoobj=std::make_shared("foo",1);因此我采用了这段代码:std::shared_ptrpT1(newTriangle(pCanvas,30,30,30,60,60,30,255,0,0));并将其修改为这段代码:aut

c++ - 在 switch 语句中从 int 到 enum 类的隐式转换

enumclasspid{Alpha,Beta,Gamma};intmain(){intpropId=2;switch(propId){casepid::Alpha:casepid::Beta:casepid::Gamma:break;}}以上片段在msvc2012中编译良好(并且有效)但在clang-3.4和g++-4.8中失败。这些需要static_cast(propId)在switch子句中使用。顺便说一下,没有显式转换的简单赋值,例如pida=propId;在每个编译器中给出错误。谁做对了? 最佳答案 标准第4条,“标准转换

C++ 编译错误 - ‘operator=’ 不匹配

下面的代码编译没有问题classMyClass{public:MyClass(){std::cout但是当我将赋值运算符参数更改为非常量时编译器打印错误:MyClass&operator=(MyClass&m){std::cout我想知道原因。提前致谢。 最佳答案 因为MyClass&使没有const的operator=不是正确的赋值运算符。它必须是operator=(constMyClass&)(或operator=(MyClass)但不要那样做,除非你知道自己在做什么,copy-&-swap。..).否则,您的代码d=MyCla

c++ - 为什么继承的 protected operator=() 具有公共(public)访问权限

声明为protected的重载运算符=对于继承父类作为public的子类是公开可访问的。#includeclassA{public:A(charc):i(c){}chari;protected:A&operator=(constA&rdm){std::cout编译时没有错误:$g++-Wall-otest_operator~/test_operator.cpp$./test_operatora.i==aaccessingoperator=()a.i==x直接使用A是编译不过的。operator=()以外的任何其他运算符重载都不会编译。使用g++4.4.7和7.3.0以及c++98和c+

c++ - `enable_if` 与 `enum` 模板特化问题

我在GCC编译时遇到问题enable_ifs应用于模板类方法的返回值。使用Clang,我可以在enable_if中使用表达式在enum上模板参数,而GCC拒绝编译此代码。这里是问题描述、初始代码及其后续修改,试图让我和编译器满意(不幸的是,不是同时)。我有一个非模板类Logic包含模板化类方法computeThings()它有一个enumStrategy作为其模板参数的之一。computeThings()中的逻辑取决于编译时间Strategy,所以ifconstexpr是一种合理的实现方式。变体1#includeclassLogic{public:enumStrategy{strat_

c++ - doxygen:如何记录\enum 值外线?

准确地说:我知道如何在声明时对枚举进行dox,我想改为不在线地对它们进行dox。我想让头文件没有doxygen注释;它们都在.cpp文件中。这对函数、类、typedef等来说不是问题。我还可以像这样记录enum本身:/*!\enumMyClass::MyEnumFooBarBaz\valueFirstEnumValue但是我如何记录enum的值呢?谢谢! 最佳答案 您需要根据docs使用\var 关于c++-doxygen:如何记录\enum值外线?,我们在StackOverflow上找

c++ - 在 switch 语句中使用类类型 : is it better than using typeid operator?

我在下面看到了有关C++标准$6.4.2中switch语句的内容。Switch语句可以带一个条件。Theconditionshallbeofintegraltype,enumerationtype,orofaclasstypeforwhichasingleconversionfunctiontointegralorenumerationtypeexists(12.3).Iftheconditionisofclasstype,theconditionisconvertedbycallingthatconversionfunction,andtheresultoftheconversion

c++ - 这个 operator() 语法有什么作用?

这段代码取自http://drdobbs.com/cpp/184403774:templateclassMinResult{L&lhs_;R&rhs_;public:operatorL&(){returnlhs_上面的代码试图在箭头指向的线上做什么?我是C++的初学者,我知道我们可以通过定义operator()来覆盖/定义它。但是不应该这样定义吗L&operator(){returnlhs_我确信这是一些不同的语法,因为operator()应该是一个词。此外,您不能用不同的返回类型定义其中两个。 最佳答案 不,这是类型转换运算符。你