草庐IT

int_void

全部标签

c++ - 没有从 long unsigned int 到 long unsigned int& 的转换

当我尝试编译以下内容时,收到错误消息Noknownconversionforargument2fromlongunsignedinttolongunsignedint&代码:voidbuild(int*&array,unsignedlong&index){if(index==0)return;else{heapify(array,index);build(array,index-1);}}谁能解释为什么会这样,这个错误背后的逻辑是什么? 最佳答案 build的第二个参数需要引用(用&标记)。引用有点像指针,因此您只能使用具有内存地址

c++ - 如何在 C++ 中调用 void foo(int (&)[]) {}?

voidf1(int(&)[8]){}voidf2(int(&)[]){}intmain(){inta[8];f1(a);//OKf2(/*WhatshouldIputhere?*/);//???return0;}如何调用f2?PS:voidf2(int(&)[]){}在VC++2012下是合法的。考虑以下几点:templatestructA{};templatestructA{};templatestructA{}; 最佳答案 C++有一个明确的规则,不允许将没有边界的数组引用或指针作为参数(但这些是其他有效类型)。以下将是此类参

c++ - (void)变量的意义

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:Whatdoesvoidcastingdo?我刚刚浏览了一个项目,发现了这个//Thisisina.cppfile#ifxxx==5(void)var;#endif这个(void)var有什么作用?这样做有什么意义。我听说这与编译有关。添加c和cpp标签以防这种情况很常见。

C++:通过隐式构造函数初始化 int 变量

我正在学习C++,我对int变量的初始化有点困惑。此代码(包括注释)是Nawaz在本主题WhydoesC++requireauser-provideddefaultconstructortodefault-constructaconstobject?中的回答的复制/粘贴。structPOD{inti;};PODp1;//uninitialized-butdon'tworrywecanassignsomevaluelateron!p1.i=10;//assignsomevaluelateron!PODp2=POD();//initialized对于p2,我知道发生了以下情况:调用默认构造

c++ shared_ptr 从 char* 到 void*

我正在尝试将char*字符串传递给将在线程内执行的函数。该函数具有以下原型(prototype):voidf(void*ptr);线程分配由类似于以下的函数进行:voidappend_task(std::function&f,void*data);我想分配一个将在线程内部使用的字符串。现在我有这个:stringname="randomstring";char*str=newchar[name.length()];strcpy(str,name.c_str());append_task(f,static_cast(str));我想放弃手动分配和解除分配内存的义务。我如何使用std::sh

c++ - std::stack<int> 具有最大功能?

如何实现stack使用最大操作,最大函数的复杂度为O(1)并且它使用O(n)额外内存? 最佳答案 想法是通过在堆栈中使用对来跟踪最大值。如果你向堆栈中插入一些东西,你会相应地更新最大值。classStack{private:stack>s;public:boolempty()const{returns.empty();}intmax()const{assert(empty()==false);returns.top().second;}intpop(){intans=s.top().first;s.pop();returnans;}

c++ - 从魔数(Magic Number)到 int 或 long 的重载解析(在 range-v3 中)

在range-v3中,view_facade类有begin()函数。template())>detail::facade_iterator_tbegin(){return{range_access::begin_cursor(derived(),42)};}range_access::begin_cursor()是这样实现的,templatestaticRANGES_CXX14_CONSTEXPRautobegin_cursor(Rng&rng,long)//--1RANGES_DECLTYPE_AUTO_RETURN(rng.begin_cursor())templatestatic

c++ - 初始化 int 影响函数返回值

很抱歉这个问题的标题含糊不清,但我不确定如何准确地提出这个问题。以下代码在Arduino微处理器(为ATMega328微处理器编译的c++)上执行时运行良好。返回值显示在代码的注释中://ReturntheindexofthefirstsemicoloninastringintdetectSemicolon(constchar*str){inti=0;Serial.print("i=");Serial.println(i);//prints"i=0"while(i如预期的那样,这会输出“2”作为第一个分号的位置。但是,如果我将detectSemicolon函数的第一行更改为inti;即

c++ - 函数需要参数并返回指向 void 函数的指针

我有几个void函数在我的代码中做一些重要的事情。voidfunction1(Myclassclass1,intmyvar){//dosomestuff}voidfunction2(Myclassclass1,intmyvar){//dosomeotherstuff}//...maybesomemoresimilarfunctions我想创建一个函数,它会根据我传递的参数返回指向这些函数中的任何一个的指针。我不知道该怎么做。我想要类似的东西void*choosefunction(inti,intj){if(i==j)return(void*)function1;elsereturn(v

c++ - 如何在 int 类型的二维 vector 中 push_back 数据

我有一个vector,想在运行时将int数据存储到其中,我可以用这种方式将数据存储在2Dvector中吗?std::vector>normal:for(i=0;i 最佳答案 是的,但您还需要插入每个子vector:std::vector>normal;for(inti=0;i());for(intj=0;j 关于c++-如何在int类型的二维vector中push_back数据,我们在StackOverflow上找到一个类似的问题: https://stack