草庐IT

non-assignable

全部标签

c++ - 错误 [Pe513] : a value of type "void *" cannot be assigned to an entity of type "uint8_t *"

我正在尝试将C项目转换为C++。在C项目中,我在编译成C++时遇到了这个错误:Error[Pe513]:avalueoftype"void*"cannotbeassignedtoanentityoftype"uint8_t*"下面的代码给出了这个错误:#defineRAM32Boundary0x20007D00uint8_t*pNextRam;pNextRam=(void*)RAM32Boundary;//loadupthebaseram谁能解释一下这是在C中做什么以及如何将其转换为C++? 最佳答案 C允许与void*之间的隐式转

c++ - 匈牙利算法 : I'm having trouble with assigning as many jobs to workers as possible

我已经在C++中创建了匈牙利算法的实现。这种实现在很多情况下都非常有效。但是,在某些情况下,我的算法根本不起作用,因为我相信(并且确实如此)我对算法的一个步骤的实现是错误的。我的实现将数组X作为输入,运行算法的步骤并产生最终分配。该算法的步骤可以在维基上找到:HungarianAlgorithm在步骤3中,它具有以下成本数组(worker由行表示,作业由列表示)然后它说Initiallyassignasmanytasksaspossiblethendothefollowing但是我不明白什么是正确的实现。如何分配尽可能多的任务?选择会是随机的吗?然后如果选择是随机的,我可以选择第一个w

c++ - (Re)Using std::algorithms with non-standard containers

我有一个“列”容器类型:structMyColumnType{//Data:Eachrowrepresentsamemberofanobject.vectora;//Allvectorsareguaranteedtohavealwaysvectorb;//thesamelength.vectorc;voidcopy(intfrom_pos,intto_pos);//Thecolumntypeprovidesaninterfacevoidswap(intpos_a,intpos_b);//forcopying,swapping,...voidpush_back();//Andforres

c++ - MSVC : modifiers not allowed on non-memberfunction

我在linux下编写了一个信号/插槽库(Codeprojectarticlehere),同时使用Clang3.5和GCC4.9进行编译。它在两个编译器上编译时都没有警告(也在3.4版和4.8版上)。当我完成所有工作并将文章发布到网上时,没过多久我就收到投诉说它不能在MSVC上工作。(VisualStudioExpress2013?对不起,我对版本控制系统不熟悉。)我把它安装在虚拟机中自己看了一下,发现它不会编译以下内容:templatestructRemoveCV;templatestructRemoveCV{usingType=R(Args...);};templatestructR

c++ - libc++ 与 VC++ : Can non-UTF conversions be done with wstring_convert?

C++11的std::wstring_convert效果很好*用于标准UTF-8UTF-16/UCS2/UCS4转换。但是,当我尝试使用不是来自的构面实例化wstring_convert或wbuffer_convert时,它没有按预期工作://worksasexpectedstd::wstring_convert>ucs4conv;//Now,byanalogy,Iwanttotrythis:std::wstring_convert>gbconv(newstd::codecvt_byname("zh_CN.gb18030"));Clang++错误提示“在~wstring_convert

c++ - 隐式转换 : const reference vs non-const reference vs non-reference

考虑这段代码,structA{};structB{B(constA&){}};voidf(B){cout这compilesfine,运行良好。但是,如果我将f(B)更改为f(B&),它doesn'tcompile.如果我写f(constB&),它又是compilesfine,运行良好。原因和道理是什么?总结:voidf(B);//okayvoidf(B&);//errorvoidf(constB&);//okay对于每种情况,我想听听语言规范中的原因、基本原理和引用资料。当然,函数签名本身并没有错。A隐式转换为B和constB&,但不会转换为B&,这会导致编译错误。

c++ - 在调用 vector::assign() 之前调用 vector::reserve() 会更好吗?

我知道使用“reserve”以避免不必要的重新分配是一种很好的做法(EffectiveSTL的第14项):std::vectorv1;v1.reserve(1000);for(inti=0;i当您调用assign时是否适用相同的规则?std::vectorv2;//v2.reserve(v1.size());//Bettertodothis?v2.assign(v1.begin(),v1.end()); 最佳答案 如果v1是std::vector你真的不需要它,因为编译器/STL知道在v2(并且将在复制实际数据之前保留本身所需的数量

c++ - 为什么不能实例化带有 "non const"复制构造函数的对,而没有实例化一对是可能的?

假设您有以下类(class):structA{A(){}A(A&)=delete;};intmain(){std::pairp1;return0;}以下代码将无法编译(使用-std=c++11和g++)并出现以下错误:/usr/include/c++/5/bits/stl_pair.h:Ininstantiationof‘structstd::pair’:test.cpp:13:23:requiredfromhere/usr/include/c++/5/bits/stl_pair.h:127:17:error:‘constexprstd::pair::pair(conststd::pa

c++ - 错误 : invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector<bool>::reference {aka std::_Bit_reference}’

为什么我会收到错误:从类型为“std::vector::reference{akastd::_Bit_reference}”的右值对类型为“bool&”的非常量引用进行无效初始化?vector>vis;bool&visited(intx,inty){returnvis[x][y];//error}据我所知,vector中的operator[]返回引用,所以它应该是一个左值,但它不起作用。我应该怎么做才能让它发挥作用? 最佳答案 那是因为std::vector不是它看起来的样子。std::vector有一个特化与类型bool-它是空间

c++ - 错误 : cannot convert 'const wchar_t [13]' to 'LPCSTR {aka const char*}' in assignment

//includethebasicwindowsheaderfile#include#include//theWindowProcfunctionprototypeLRESULTCALLBACKWindowProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam);//theentrypointforanyWindowsprogramintWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){//thehandleforthew