草庐IT

forward_static_call

全部标签

c++ - 错误 C4996 : 'std::_Copy_impl' : Function call with parameters that may be unsafe

我知道这个问题在SO中被问过很多次,但这是与其他问题的不同。CompilerError:FunctioncallwithparametersthatmaybeunsafeVisualStudioWarningC4996xutility(2227):warningC4996:'std::_Copy_impl'失败的代码片段DWORDdwNumberOfNames=pExportDirectory->NumberOfNames;LPDWORDdwNames=(LPDWORD)((LPBYTE)hDLL+pExportDirectory->AddressOfNames);std::vecto

c++ - 如何将类型的名称作为字符串嵌入到 static_assert() 中?

这个问题在这里已经有了答案:Integratetypenameinstatic_assertoutput?(4个答案)关闭8年前。问题以下内容不会生成,因为消息不是字符串文字。templatestructFoo{Foo(){static_assert(is_pod::value,typeid(T).name());}};最终,如果我尝试编译Foofb;,我想要一条失败消息,如“Barmustbeapod-type”.是否可以按照static_assert的要求在编译期间构建此字符串?

C++11 std::forward_as_tuple 和 std::forward

当我将它们用作std::forward_as_tuple的参数时,我是否应该std::forward我的函数参数?templatevoidfn(List&&...list){//doIneedthisforward?call_fn(forward_as_tuple(forward(list)...));}我知道它们将被存储为右值引用,但还有什么我应该考虑的吗? 最佳答案 您必须使用std::forward以保留fn()参数的值类别。由于参数在fn中有一个名称,它们是左值,并且在没有std::forward的情况下,它们将始终照原样传

c++ - 为什么不总是使用 std::forward?

std::move和std::forward之间的区别是众所周知的,我们使用后者来保存转发对象的值类别,而前者用于转换为右值引用以启用移动语义。在effectivemodernC++中,有一个指南指出usestd::moveonrvaluereferences,std::forwardonuniversalreferences.然而在以下场景中(以及我们不想更改值类别的场景),templatevoidf(vector&&a){some_func(std::move(a));}其中a不是转发引用而是简单的右值引用,执行以下操作不是完全相同吗?templatevoidf(vector&&a

c++ - 将 std::make_tuple 与重载函数一起使用时如何避免 static_cast

g++说error:toomanyargumentstofunction'constexprstd::tuple如果我在std::make_tuple调用中省略了static_cast#includetypedefint(*func_t)();intnumber(){return2;}doublenumber(boola){return1.2;}intmain(){//Withastatic_castitcompileswithoutanyerror//std::tupletup=std::make_tuple(static_cast(number));std::tupletup=st

C++ Java static final 等价物

我正在使用C++编写国际象棋游戏程序。我想为类Board创建两个类属性:ROWS和COLUMNS。在Java中,我会将它们声明为staticfinal,一切都会按我的意愿运行。我如何在C++中做同样的声明?我需要在其他类中通过“Board::ROWS”和“Board::COLUMNS”访问这些属性。我所拥有的是这个,它抛出编译错误,因为ROWS和COLUMNS没有在m_TileMap的声明范围内声明。在不使用#define语句的情况下执行此操作是否有好的做法?classBoard{Tile*m_TileMap[ROWS][COLUMNS];public:staticconstintRO

c++ - 使用 static_cast 处理混合(基础和派生)对象的 vector 是否存在性能风险? (又名 "it this a dumb idea?")

给定基类gameObject和派生类animatedGameObject,我认为将它们的所有实例存储在std::vector。如果vectorGameObjects声明为gameObject*的基类型,则派生对象实例需要强制转换。例子:vectorGameObjects;gameObjectA*=newgameObject(...init...);animatedGameObjectB*=newanimatedGameObject(...init...);GameObjects.push_back(A);GameObjects.push_back(B);//toaccesstheani

c++ - 铛++ : error: call to 'partition' is ambiguous

#include#includetemplateBidirectionalIteratorpartition(BidirectionalIteratorfirst,BidirectionalIteratorlast,UnaryPredicatepred){while(first!=last){while(pred(*first)){++first;if(first==last)returnfirst;}do{--last;if(first==last)returnfirst;}while(!pred(*last));std::swap(*first,*last);++first;}re

c++ - static_cast 转换构造函数 vs 转换运算符

这个问题在这里已经有了答案:Shouldn'tthiscodethrowanambiguousconversionerror?(1个回答)关闭6年前。看完this我尝试使用static_cast进行此类转换:classA;classB{public:B(){}B(constA&)//conversionconstructor{cout(a);return0;}我预计它不会编译,因为构造函数和运算符都具有相同的c-v资格。然而,它编译成功,static_cast调用构造函数而不是运算符。为什么?(使用带有pedantic和Wall标志的gcc4.8.1编译)

c++ - 线程错误 : invalid use of non-static member function

这个问题在这里已经有了答案:Passingmemberfunctionstostd::thread[duplicate](2个答案)关闭5年前。我想了解C++中的线程,但我不知道如何解决这个问题。我想调用两个线程来运行名为“createS”的函数,但出现此错误:error:invaliduseofnon-staticmemberfunction我读过关于这个主题的其他问题,但我真的不明白如何让我的代码工作。有人可以向我解释我做错了什么并尝试帮助我找到解决方案吗?test_class.cppvoidtest_class::generateS(){map1=newmultimap>;map