草庐IT

this_project

全部标签

c++ - 是否编译了带有 if(this==NULL) 测试的类函数?

我在我们的实验中看到了这段代码片段,它实际上是在MSVC2008和G++中编译的。voidLinkList::Insert(Tn){if(this==NULL)//somecodehere}据我所知,this不能为null,因为如果未实例化,则不能在C++中调用类函数。这是一个有效的代码吗?如果是这样,背后的原因是什么?它可以用在什么地方? 最佳答案 sinceyoucannotcallaclassfunctionsinc++ifitwasn'tinstantiated问题是,你可以,但它leadstoundefinedbehavi

c++ - 'giving out' 是构造函数中对 'this' 的引用吗?

我的代码:Scene::Scene(conststd::string&scene_file):ambient_light(0,0,0),background(0,0,0){scene_parserparser(*this);parser.parse(scene_file);}scene_parser是Scene的friend,在parse方法中它访问(r/w)Scene的成员。这会导致任何问题吗? 最佳答案 是的,给出对this的引用是可以的。但是,您通常希望在其他对象稍后使用该指针时执行此操作。您的用例看起来会在构造函数完成之前立

c++ - 这个私有(private)变量 "not declared in this scope"怎么样?

我目前正在尝试学习更多有关C++面向对象设计的知识(熟悉Java),但遇到了一些困难。我试图将这个项目放在一起,以在使用SFML构建图形和音频的游戏中学习这些原则。我有以下两个文件。WorldObject.h#ifndefWORLDOBJECT_H#defineWORLDOBJECT_H#include#include#include"ImageManager.h"classWorldObject{private:sf::Sprite_sprite;voidSetImagePath(std::stringpath);sf::SpriteGetGraphic();};#endif世界对象

c++ - 带有 "Do not show this again"复选框的 QMessageBox

如何在下方显示带有“不再显示”复选框的消息框?我想象的东西看起来像这样: 最佳答案 Qt5.2添加了将QCheckBox添加到QMessageBox的可能性。看看QMessageBox::setCheckbox这是一些演示代码if(this->showMsgBox){QCheckBox*cb=newQCheckBox("OkayIunderstand");QMessageBoxmsgbox;msgbox.setText("AmInerve-wrecking?");msgbox.setIcon(QMessageBox::Icon::Q

c++ - 构造函数内部 "this"的 dynamic_cast

这个问题与这个问题非常相似Whycan'tIdynamic_cast"sideways"duringmultipleinheritence?,除了强制转换确实有效-只是不在构造函数中。标题:classA{public:virtual~A(){}voidprintA();};classB{public:B();virtual~B(){}voidprintB();private:std::stringmessage_;};classC:publicA,publicB{public:C(){}virtual~C(){}};来源:voidA::printA(){cout(this);if(a)

c++ - 在成员函数尾随返回类型中使用 this 和属性?

在此answer我给出了,在尾随返回类型中使用this和类_arg的属性作为decltype表达式的一部分是有意义的。可以不用,但不方便。既不是clang3.0(见下文)也不是gcc4.5.2不过还是接受了。#includeclassMyClass{public:MyClass(inti):_arg(i){}templateautoapply(F&f)->decltype(f(_arg)){returnf(_arg);}templateautoapply(F&f)->decltype(f(*this,_arg)){returnf(*this,_arg);}private:int_arg

c++ - 给定表达式 : `cond ? *this : throw()` 返回对类型的引用时出错

这似乎是一个错误,但我只是想确认一下。下面的格式是否正确?如果不是,为什么不呢?#includestructX{intvalue;constexprX(intvalue):value(value){}constexprX&do_something(intx){returnx在使用默认解决方案开关的VC++2015R3下,我得到:warningC4172:returningaddressoflocalvariableortemporaryg++(GCC)5.4.0带有开关-Wall-pedantic我得到:error:invalidinitializationofnon-constref

C++ 编译器错误 "was not declared in this scope"

我在尝试编译C++UDP客户端程序时遇到奇怪的编译器错误。g++-oclientUdp.cppClientMain.c-I.-lpthreadInfileincludedfromClientMain.c:1:0:Udp.h:Indestructor‘CUdpMsg::~CUdpMsg()’:Udp.h:103:43:error:‘free’wasnotdeclaredinthisscopeUdp.h:Inmemberfunction‘voidCUdpMsg::Add(in_addr_t,constvoid*,size_t)’:Udp.h:109:34:error:‘malloc’was

c++ - 为什么有些类方法返回 "*this"(自身的对象引用)?

在Internet上(也特别是在这里,在stackoverflow上)有很多返回*this的解释代码。例如来自帖子Copyconstructorand=operatoroverloadinC++:isacommonfunctionpossible?:MyClass&MyClass::operator=(constMyClass&other){MyClasstmp(other);swap(tmp);return*this;}当我将交换写为:voidMyClass::swap(MyClass&tmp){//somecodemodifying*thisi.e.copyingsomearray

XCode Project-从GitHub到Mac的同步远程存储库

我正在从事一个工作项目,也想在家中进行工作。我将Xcode项目与远程存储库同步到我的工作Mac中。我想知道如何在我的房屋的Mac上获得副本并同步它,以便我能够推动并拉动?看答案一个简单的gitclonehttps://....yourRepositoriy/ongithub您必须使用终端安装的git运行应该工作并将所有文件复制到您的本地计算机