草庐IT

out_of_range

全部标签

c++ - 与零长度参数一起使用的 memset : ignore or watch out?

在链接动态库时,我无法找到有关以下警告的任何信息:Infunction`MyClass::myfunc()':MyClass.cpp:(.text+0x14e4):warning:memsetusedwithconstantzerolengthparameter;thiscouldbeduetotransposedparameters这是myfunc的摘录:voidMyClass::myfunc(){vector::const_iteratorit;for(it=m_vars.begin();it!=m_vars.end();++it){if((*it)->recordme){MyRe

c++ - 错误 :incompatible types in assignment of 'const char[5]' to 'char[10]'

我已经将c定义为charc[][10]在函数定义中并像c[i]="gray";一样使用它怎么了?我在网上搜索,它显示相同的语法。谢谢。 最佳答案 您不能对数组使用赋值(=)。如果将c更改为指针数组,这可能会起作用,具体取决于您需要使用它做什么。constchar*c[20];c[i]="gray";或者如果声明的类型必须是数组的数组,您可以使用strncpy:charc[20][10];strncpy(c[i],"gray",sizeof(c[i])); 关于c++-错误:incompa

c++ - 错误 : redefinition of class

这是我的代码://inmain.cpp#include"iostream"#include"circle.cpp"#include"rectangle.cpp"#include"shape.cpp"usingnamespacestd;intmain(){Shapeshapes[10];for(inti=0;iwidth=width;}virtualvoidsetHeigth(intheight){this->height=height;}};//inshape.cppclassShape{public:virtualintgetArea()const=0;};编译时,我得到这个错误:e

c++ - 错误 : Variable length array of Non-POD element type 'string'

在开始之前,我必须首先声明,我已经研究过针对此错误的可能解决方案。不幸的是,它们都与不使用数组有关,这是我项目的要求。另外,我目前正在学习CS入门类(class),所以我的经验几乎没有。数组的用途是从文件中收集名称。因此,为了初始化数组,我计算了名称的数量并将其用作大小。问题是标题中所述的错误,但我仍然使用一维数组时看不到解决方法。主要.cpp#include#include#include#include#include#include"HomeworkGradeAnalysis.h"usingnamespacestd;intmain(){ifstreaminfile;ofstrea

c++ - 为什么我无法在 range-v3 中获取范围的大小?

我想获取姓名以“T”开头的人数:#include#include#includeusingnamespaceranges;intmain(){constautonames=std::vector{"Tony","Peter"};std::cout但是我遇到了巨大的编译错误:λclang-std=c++14test.cpptest.cpp:11:18:error:nomatchingfunctionforcalltoobjectoftype'constranges::v3::adl_size_detail::size_fn'std::cout,std::allocator>>>>,std

Xamarin.Forms of StrativitivityForresult的替代方案

我目前正在尝试从A中选择URIRingtoneManager.ActionRingtonePicker。我放入所有额外的设置,并设置适当的标志。但是我只能打电话StartActivity(intent)。无论如何,我可以从铃声选择器中获得选择intent.getParceableExtra(RingtoneManager.ExtraRingtonePickedUri);。我的代码在下面,如果我可以替换context.StartActivity(intent)随之而来的是,那将很棒。publicasyncTaskpickAndReceiveRingtone(stringcurrentUri){I

c++ - 忽略注释 : offset of packed bit-field without using "-Wno-packed-bitfield-compat"

当我尝试编译以下union时,弹出此警告:10:5:note:offsetofpackedbit-field'main()::pack_it_in::::two'haschangedinGCC4.4#pragmaGCCdiagnosticignore"-Wpacked-bitfield-compat"unionpack_it_in{struct{uint8_tzero:3;uint8_tone:2;uint8_ttwo:6;uint8_tthree:4;uint8_tfour:1;}__attribute__((packed))u8_2;uint16_tu16;};#pragmaGCC

c++ - 将 "Out of Memory"错误写入文件,没有内存?

如果程序内存不足,我想记录并可能警告用户,让他们有机会尝试释放一些内存(希望如此)。虽然我可以预先分配显示情况所需的必要GUI实体,但我担心的是,在这种情况下可能无法使用cstdio进行更多基本操作,例如打开或写入文件。我的问题是,如果一个程序根本不能再动态分配内存,是否仍然可以使用cstdio?是否需要采取任何特殊措施,例如预先打开文件或将其设置为不使用缓冲区?cstring函数仍然可以运行吗?在这种情况下还有其他可能需要了解的障碍吗?(在这种情况下警告用户是一种奢侈,主要目的是将错误记录到文件中,然后尝试使用cstdio挽救相关数据,然后按此顺序警告用户)

python - C++ python API : second call of PyImport_Import results in SIGSEGV

我正在尝试通过cApi从c++调用python,以获取c++中两个numpy数组的值。第一次调用我的程序callPython()时,一切似乎都运行良好,但第二次调用导致SIGSEGV时pModule=PyImport_Import(pName);被执行。在flebool的回答中,有一个比我的简单得多的最小示例代码,但有同样的错误。最小.cpp#include#includelongintgeTuple(PyObject*pValue,PyObject*objI,inti){objI=PyTuple_GetItem(pValue,i);longintn,M;double*xJ;if(ob

c++ - JNI_CreateJavaVM : Buffer overrun if I throw an exception in case of failure

在C++项目中,我使用JNI调用API来启动JVM。我已经围绕JVM做了一些包装,因此我可以以面向对象的方式使用所有需要的部分。到目前为止效果很好。现在,如果JVM没有启动(JNI_CreateJavaVM返回值JNI_CreateJavaVM之后抛出异常,我遇到缓冲区溢出。如果我在没有JNI_CreateJavaVM调用的情况下引发异常,它会按预期工作。有人知道这里的问题是什么吗?或者如何调试?环境:Windows、VisualStudio2008JDK:jrockit27.6jdk16005,但也发生在SUNstockone上干杯多米尼克 最佳答案