草庐IT

THIS_ARCH

全部标签

c++ - 静态对象的this指针

如果我在静态对象中获取this并将其存储在Singleton对象的vector中,我可以假设指针在程序的整个生命周期内都指向该对象吗? 最佳答案 一般来说,您不能这样假设,因为在不同翻译单元中静态对象的创建顺序是未指定的。在这种情况下它会起作用,因为只有一个翻译单元:#include#includeclassA{A()=default;A(intx):test(x){}A*constget_this(void){returnthis;}staticAstaticA;public:staticA*constget_static_thi

c++ - "This application has requested the Runtime to terminate it in an unusual way."

当我关闭Qt程序(g++4.4.0)时,出现MicrosoftVisualC++RuntimeLibrary错误“此应用程序已请求运行时以异常方式终止它”。但是当我在调试器中运行它时,我没有收到错误消息。有谁知道如何获取有关崩溃的一些信息?消息框只有一个确定按钮。编辑添加:按照Wimmel的建议,我附加到调试器。有两个线程还活着,ThreadID为1和3。堆栈看起来像这样:LevelFunctionFileLineAddress0VTagOutputC:\Windows\syswow64\user32.dll00x7529438d1VTagOutputC:\Windows\syswow

c++ - 子类和 get_shared_from_this()

我需要找到一个解决方案来允许子类获得其正确的智能指针。classParent:publicenable_shared_from_this{...}classChild:publicParent{publicChild(){boost::shared_ptrpointer=shared_from_this();//shouldworkboost::shared_ptrpointer=shared_from_this();//won'twork....}如何使用shared_from_this()获取正确的智能指针?背景:我正在写一些通知程序/监听器的东西,有些类自然需要从通知程序注册和注

C++智能指针enable_shared_from_this

enable_shared_from_this介绍enable_shared_from_this其实是智能指针中的内容,它的作用就是用于在类的内部,返回一个this的智能指针。对于enable_shared_from_this,初学者可能不明白它的使用场景和使用的必要性,可能有得童鞋们会问既然有了this这个指向自己的指针,为什么还需要enable_shared_from_this这个东西呢,直接用this代替不就好了吗?我们来看看以下代码例子,如果先不运行,你能看出什么问题吗?#includeclassPerson{public:Person()=default;~Person(){};st

c++ - C 和 Matlab : Why does this one line in Matlab become so many lines in C++ code generated by Matlab Coder?

我有一些运行了数百万次的Matlab代码,如以下问题所述:Matlab:Doescallingthesamemexfunctionrepeatedlyfromaloopincurtoomuchoverhead?我正在尝试对其进行混合以查看是否有帮助。现在,当我使用MatlabCoder工具从Matlab代码生成代码时,代码通常是合理的,但是这一行Matlab代码(在下面第一行的C++注释中)导致了这种怪异,我不知道为什么。任何有助于理解和降低其复杂性的帮助将不胜感激。对于context,d是一个二维矩阵,s1是一个行vector。s1_idx在前面的C++代码中被指定为length(s

c++ - "error: ' avcodec_open ' was not declared in this scope"尝试编译 untrunc

我有一个断电的摄像机录制的视频。因此,它制作的带有H.264编解码器的MP4文件已损坏。我想在Ubuntu14.04.1中修复这个文件。我见过的一种方法suggested就是用untrunc.我正在尝试编译它,但遇到了一个我不知道如何解决的错误。到目前为止我所做的如下:sudoapt-getinstalllibavformat-devlibavcodec-devlibavutil-devgitclonehttps://github.com/ponchio/untrunc.gitcduntrunc/g++-ountruncfile.cppmain.cpptrack.cppatom.cpp

c++ - Qt错误: `qApp' was not declared in this scope

据我所知,qApp是全局指针,因此它应该可以在任何地方访问,但我收到此错误error:qAppwasnotdeclaredinthisscope。1#include"textEdit.h"23TextEdit::TextEdit(){4}56voidTextEdit::insertFromMimeData(constQMimeData*source){7if(qApp->mouseButtons()==Qt::MidButton){8return;9}10QTextEdit::insertFromMimeData(source);11}1213 最佳答案

c++ - 设置跳转/长跳转 : Why is this throwing a segfault?

下面的代码总结了我目前遇到的问题。我当前的执行流程如下,我在GCC4.3中运行。jmp_bufa_buf;jmp_bufb_buf;voidb_helper(){printf("enteringb_helper");if(setjmp(b_buf)==0){printf("longjmpingtoa_buf");longjmp(a_buf,1);}printf("returningfromb_helper");return;//segfaultsrighthere}voidb(){b_helper();}voida(){printf("setjmpinga_buf");if(setjm

c++ - 什么时候需要 'this'?

是否需要this指针?如果您在功能上传递this指向的类的实例,我想您会需要它。但是就设置/检索/调用/任何成员而言,this总是可选的吗?我已经标记了这个C++,因为这是我特别想知道的语言,但是如果有人可以确认该构造对于Java和其他使用this指针的OO语言是相同的,不胜感激。 最佳答案 我能想到的三种情况:当你只想传递一个指向当前类的指针时:classB;structA{B*parent_;A(B*parent):parent_(parent){}};structB{A*a;B():a(newA(this)){}};在构造函数

c++ - 使用 "delete this"删除当前对象是否可以?

我正在编写一个链表,我希望一个结构的析构函数(一个Node结构)简单地删除自身,并且没有任何副作用。我希望我的列表的析构函数在其自身上迭代调用节点析构函数(临时存储下一个节点),如下所示://mylistclasshasfirstandlastpointers//andmynodeseachhaveapointertothepreviousandnext//nodeDoublyLinkedList::~DoublyLinkedList{Node*temp=first();while(temp->next()!=NULL){deletetemp;temp=temp->next();}}所