草庐IT

this-reference

全部标签

c++ - "Undefined reference to"链接目标文件时出错

这个问题在这里已经有了答案:"undefinedreferenceto"errorswhenlinkingstaticClibrarywithC++code(1个回答)关闭6年前。我意识到这个问题已经以多种方式提出,包括thisverycomprehensiveanswer但我看了很多,并尝试修复我的错误,但无济于事。我正在使用.cpp和.c文件来创建程序。我用g++编译了所有文件,它似乎没有更多的链接错误,尽管它给了我一堆与C语法相关的C++错误。这是我使用的命令:g++-oprogrammain.cpp/data/*.c-l[...libs]main.cpp调用.c文件中的函数。然

c++ - 尝试与 typedef 交 friend 时出现 "elaborated type refers to typedef"错误

假设我有以下代码(一个简单的CRTP类层次结构)。我想对基类类型进行typedef以节省自己的输入(在我的实际代码中,我多次使用基类类型并且基类采用多个模板参数),并且我需要与基类交friend,因为我想保留实现私有(private)。templateclassBase{public:voidfoo(){*static_cast(this)->foo_i();}};templateclassDerived:publicBase>{public:typedefclassBase>BaseType;private://Thishereistheoffendinglinefriendclas

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++ - 为什么以不同的顺序使用 std::remove_reference 和 std::remove_const 会产生不同的结果?

在下面的代码中,我使用了std::remove_const和std::remove_reference但在两种情况下以不同的顺序给出了不同的结果:#include#include#include#include#includeusingnamespacestd;intmain(){vectorar={"mnciitbhu"};cout::type>::typeTT;cout::value::value::value::type>::typeTT;cout::value::value::value输出是:Firstcase:truefalsefalseSecondcase:falsetr

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++ - std::decay 和 std::remove_reference 之间的区别

在用C++做模板元编程的时候,经常遇到类似下面的情况:templateSmake_wrapper(T&&t){returnS(std::forward(t));}我知道我应该在返回类型中使用类似std::decay的东西,但为什么std::remove_reference不能正常工作?这里有什么区别?std::remove_cvref怎么样? 最佳答案 举个例子#includeintmain(){static_assert(std::is_same_v,std::remove_reference_t>);//int!=constin

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();}}所

【C++初阶】三、类和对象(面向过程、class类、类的访问限定符和封装、类的实例化、类对象模型、this指针)

=========================================================================相关代码gitee自取:C语言学习日记:加油努力(gitee.com) =========================================================================接上期:【C++初阶】二、入门知识讲解(引用、内联函数、auto关键字、基于范围的for循环、指针空值nullptr)-CSDN博客 ===================================================

c++ - 为什么我无法通过 lambda 捕获 "this"指针?

考虑以下代码:classA{public:voidfoo(){autofunctor=[this](){A*a=this;autofunctor=[a]()//Thecompilerwon'taccept"this"insteadof"a"{a->bar();};};}voidbar(){}};在VC2010中,使用this代替a会导致编译错误。其中:1>main.cpp(20):errorC3480:'`anonymous-namespace'::::__this':alambdacapturevariablemustbefromanenclosingfunctionscope1>m