草庐IT

pointer_traits

全部标签

c++ - 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str':非标准语法;使用 '&' 创建指向成员的指针

我正在尝试创建一个可以读取和编译opengl顶点和片段着色器文件的函数,但是我收到了这个错误:'std::basic_string,std::allocator>::c_str':non-standardsyntax;use'&'tocreateapointertomember我不太确定如何修复它。这是我的代码:GLuintshader_load(constGLchar*vertex,constGLchar*fragment){std::stringver=file_read_all(vertex);std::stringfrag=file_read_all(fragment);con

c++ - 函数模板 : Different specializations with type traits

考虑到类模板,可以使用类型特征和虚拟启动器模板参数为某些类型的组提供模板特化。我已经askedthatearlier.现在,对于函数模板,我需要同样的东西:即,我有一个模板函数,并且想要对一组类型进行特化,例如,作为类X的子类型的所有类型>。我可以用这样的类型特征来表达这一点:std::enable_if::value>::type我想过这样做:templatevoidfoo(){//Dosomething}templatevoidfoo::value>::type>(){//Dosomethingdifferent}但是,这不起作用,因为函数模板不允许偏特化。那怎么办呢?也许是类型特

c++ - 编译错误 : base operand of ‘->’ has non-pointer type ‘Token’

我在尝试编译我的C++代码时遇到标题中提到的错误。我无法理解我在这里做错了什么。编译器在我执行booloperator==(Token)函数时出现问题。我认为这是使运算符(operator)重载的方法。关于为什么编译器不喜欢我提到的任何线索this->terminal还是this->lexeme?classToken{public:tokenTypeterminal;std::stringlexeme;Token*next;Token();booloperator==(Token&t);private:intlexemelength,line,column;};boolToken::o

c++ - 从 ‘void’ 到非标量类型的转换‘std::pair<std::basic_string<char, std::char_traits<char>

我在电子表格obj中有一堆对:std::stack>undoStack;我正在尝试弹出堆栈并将其分配给另一对:std::pairchange=spreadsheets.at(i).undoStack.pop();我收到这个错误:error:conversionfrom‘void’tonon-scalartype‘std::pair,std::allocator>,std::basic_string,std::allocator>>’requested这里出了什么问题? 最佳答案 stack::pop()返回void但您正试图将其分配

c++ - "*(pointer + integer)"在 C++ 中有什么作用?

我对这个程序中一行代码的作用感到困惑:int*temp=newint[cap];intnum=0;for(inti=name;iname、number和foo是全局变量(foo是指针),cap是一个参数。具体来说,我不明白这一行:*(temp+count)=*(foo+i);为什么会有指向括号的指针,这有什么作用? 最佳答案 *(temp+count)=*(foo+i);+运算符执行指针运算。将一个整数添加到一个指针值会产生一个新指针,该指针在原始指针之后递增了指定数量的对象。例如,如果p是指向arr[0]的指针,则p+2指向arr

c++ - 为什么专门化 type_trait 会导致未定义的行为?

讨论根据标准§20.10.2/1Header概要[meta.type.synop]:1Thebehaviorofaprogramthataddsspecializationsforanyoftheclasstemplatesdefinedinthissubclauseisundefinedunlessotherwisespecified.这个特定的子句与STL应该是可扩展的一般概念相矛盾,并阻止我们扩展类型特征,如下例所示:namespacestd{templatestructis_floating_point>:std::integral_constant::type>::value

c++ - C & C++ : What is the difference between pointer-to and address-of array?

C++11代码:inta[3];autob=a;//bisoftypeint*autoc=&a;//cisoftypeint(*)[1]C代码:inta[3];int*b=a;int(*c)[3]=&a;b和c的值相同。b和c有什么区别?为什么它们不是同一类型?更新:我将数组大小从1更改为3。 最佳答案 sizeof运算符的行为应该有所不同,其中之一,尤其是当您将a的声明更改为不同数量的整数时,例如inta[7]:intmain(){inta[7];autob=a;autoc=&a;std::cout对我来说,这会打印:428那是因

c++ - C 和 C++ : Freeing PART of an allocated pointer

假设我分配了一个指针来保存4096字节。如何在C语言中释放最后1024个字节?在C++中呢?相反,如果我想取消分配第一个1024个字节,并保留其余部分(在两种语言中)怎么办?从中间释放怎么样(在我看来,这需要将它分成两个指针,在释放区域之前和之后)。 最佳答案 不要尝试猜测内存管理。它通常比你聪明;-)您唯一可以实现的是第一个场景“解除分配”最后的1Kchar*foo=malloc(4096);foo=realloc(foo,4096-1024);但是,即使在这种情况下,也不能保证“foo”会保持不变。您的整个4K可能会被释放,并且

ios - 分配 : *** error for object: Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug in Magical record IOS

当我尝试使用MR_importValuesForKeysWithObject插入数据时,我的应用程序崩溃了:malloc:errorforobject0x174291c0e:Invalidpointerdequeuedfromfreelist.Setabreakpointinmalloc_error_breaktodebug.崩溃的代码是:+(NSArray*)MR_executeFetchRequest:(NSFetchRequest*)requestinContext:(NSManagedObjectContext*)context{__blockNSArray*results=n

ios - 将 "incompatible pointer types sending ' subclassA' 抑制为 'subclassB' 类型的参数 "clang

Xcode引发“不兼容的指针类型将‘subclassA’发送到‘subclassB’类型的参数”警告。用clang编译。在出现警告的情况下,我使用一个[subclassAisKindOfClass:[subclassBclass]]...确保兼容的指针使用。我想要这样的东西:#pragmaclangdiagnosticpush#pragmaclangdiagnosticignored"-Warc-performSelector-leaks"//warning-raisingcode#pragmaclangdiagnosticpop但对于提出适当的警告。IE。忽略指定诊断的clang标志