草庐IT

Invalid_argument

全部标签

c++ - 抽象类 : invalid abstract return type for member function ‘virtual...’

在我的程序中我有这样的类层次结构:#include#include#includeusingnamespacestd;classaa;classbb;classroot{public:virtual~root(){}virtualrootadd(constaa&a)const=0;virtualrootadd(constbb&a)const=0;};classaa:publicroot{public:aa(){}aa(constaa&a){}virtualrootadd(constaa&a)const{returnroot(newaa());}virtualrootadd(constb

c++ - Visual Studio 2010 Arduino cpp 错误 : argument of type "char *" is incompatible with parameter of type "LPCWSTR"

我正在尝试设置一个arduinouno用于与visualstudio2010中的C++程序进行串行端口通信。我正在使用此处找到的代码:http://playground.arduino.cc/Interfacing/CPPWindows不幸的是,.cpp文件在第9行为变量“portName”提供了以下消息:错误:“char*”类型的参数与“LPCWSTR”类型的参数不兼容我不明白这个错误消息,并尝试了一些不同的方法来修复它。任何帮助将不胜感激! 最佳答案 鉴于您问题中的代码链接,问题似乎出在这里:Serial::Serial(cha

c++ - 为什么我得到 "Invalid Allocation Size: 4294967295 Bytes"而不是 std::bad_alloc 异常?

我写了下面一段代码来为一个数组分配内存:try{intn=0;cin>>n;double*temp=newdouble[n];...}catch(exception&e){cout当然,我正在检查n的负值等。但是当我输入一些超过536*(10^6)的大数字时,我没有收到错误分配异常,而是收到“无效分配大小:4294967295字节”崩溃。例如我输入n=536*(10^6)-->bad-allocexception我输入n=537*(10^6)-->分配大小无效:4294967295字节-->崩溃知道为什么会这样吗? 最佳答案 调用n

c++ - 将负角度转换为正角度 : Involves invalid operand use

我正在尝试将负角度(以度为单位)转换为正角度。但是我收到一个编译错误:test.cppinvalidoperandsoftypes'double'and'int'tobinary'operator%'test.cppinvalidoperandsoftypes'float'and'int'tobinary'operator%'我的代码:doubleto_positive_angle(doubleangle){return((3600000+angle)%360);}floatto_positive_angle(floatangle){return((3600000+angle)%360

c++ - 命名管道 CreateFile() 返回 INVALID_HANDLE_VALUE,GetLastError() 返回 ERROR_PIPE_BUSY

我已经编写了一个类来处理命名管道连接,如果我创建了一个实例,关闭它,然后尝试创建另一个实例,调用CreateFile()返回INVALID_HANDLE_VALUE,并且GetLastError()返回ERROR_PIPE_BUSY。这里发生了什么?我该怎么做才能确保对Connect()的调用成功?PipeAsyncA,B;A.Connect("\\\\.\\pipe\\test",5000);A.Close();cout这是我对Connect()和Close()的实现BOOLPipeAsync::Connect(LPCSTRpszPipeName,DWORDdwTimeout){th

c++ - 为什么这段代码有 C2784 "could not deduce template argument"错误

来自Lambdafunctionpassedasparameter我可以编译示例:templateRangeFindFirstIf(Range,bool(*Function)(typenameRange::ConstReferencevalue));structrange{usingConstReference=constfloat&;};rangerng;rng=FindFirstIf(rng,[](constfloat&val){return(val当然不能链接,因为FindFirstIf没有实现。然而,当我做了类似的事情时:templateRangeMyTest(Range,Va

c++ - 这是什么意思? : note: no known conversion for argument 1 from ‘int’ to ‘const account&’

我试图理解我们通常在C++程序中遇到的错误的含义。在编译程序时我遇到了一个错误(我故意犯了这个错误,请不要告诉我如何更正它)并且存在一个注释:note:noknownconversionforargument1from‘int’to‘constaccount&’我想看懂这张纸条的意思。我的程序是:#includeclassaccount{private:inta_no;public:account(){a_no=0;}voidshowData(){std::cout我知道我还没有定义一个可以接受一个参数的构造函数,这样做会消除我的错误。好的,编译时我得到了:file1.cpp:Infu

c++ - 如何修复 "Invalid read of size 8 - 40 bytes inside a block of size 64 free' d"

m_PhyToBtMap中SPacket中的shared_ptr似乎导致“大小为8的无效读取-大小为64的block内的40字节已释放”。注意:在valgrind(下面的日志)发出此错误消息之前,它运行了将近22小时,包含数百万条消息,但我也在E​​raseAcknowledgedPackets(下面)中遇到SIGSEGV崩溃,并怀疑这是原因。我正在使用Boost1.63,因为交叉编译器不支持shared_ptr。SendMessageToBt(大小为8的无效读取)和EraseAcknowledgedPackets(大小为64的block内的40个字节已释放)在valgrind日志中被

c++ - 有没有办法在初始化字符串时避免来自 clang-tidy (fuchsia-default-arguments) 的警告?

考虑这段代码:#includeintmain(){std::stringstr="notdefault";std::cout运行clang-tidy-checks=*string.cpp给出以下内容:7800warningsgenerated./tmp/clang_tidy_bug/string.cpp:4:21:warning:callingafunctionthatusesadefaultargumentisdisallowed[fuchsia-default-arguments]std::stringstr="notdefault";^/../lib64/gcc/x86_64-p

c++ - 是什么让这个 "declarator invalid"? C++

我在vertex.h中有Vertex模板。来self的graph.h:20template21classVertex;我在我的图表模板中使用它。我已经在整个图形中成功使用了Vertex模板,返回指向顶点的指针等。现在我第一次尝试声明和实例化一个Vertex对象,gcc告诉我我的“声明符”是'无效的'。怎么会这样?81template82GraphGraph::Dijkstra(vertexs,boolprint=false)const83{84/*ConstructnewGraphwithapropriatedecorators*/85Graphspan=newGraph();86sp