草庐IT

THIS_ARCH

全部标签

c++ - 错误 : 'object' was not declared in this scope

我是C++的新手,正在尝试制作大富翁游戏。不幸的是,它仍然显示两个类之间的声明错误。我已经尝试了所有方法,但真的不知道问题出在哪里。错误:“玩家”未在此范围内声明。引擎.h#ifndefENGINE_H#defineENGINE_H#include"Player.h"#includeusingnamespacestd;classEngine{public:Engine();//methodthatstartswithgame,takerandomnumberforgettingnumberofplayers,setplayerstovectorvoidplay();//methodwh

c++ - 为什么 "this"指针用于调用派生成员函数?

在this上阅读关于虚函数的教程(与本例无关)链接,我找到了这段代码。classWeapon{public:voidfeatures(){coutWeapon::features();cout类Weapon派生自类Bomb,其中调用了Weapon的成员函数。为什么使用“this”指针调用函数Weapon::features()?这不是已经隐式给出了吗? 最佳答案 this是隐式给出的,是否显式编写通常是风格问题。在您的情况下,我会说它不会提高可读性。然而,在其他情况下,显式写入this是有意义的,甚至是必要的为了避免局部变量和数据成

c++ - BOOST_FOREACH : What is the error on using this of a STL container?

有谁知道为什么以下会在VC9上产生错误?classElem;classElemVec:publicvector{public:voidfoo();};voidElemVec::foo(){BOOST_FOREACH(Elem&elem,*this){//Dosomethingwithelem}return;}我得到的错误是:errorC2355:'this':canonlybereferencedinsidenon-staticmemberfunctions我现在拥有的唯一(hack)解决方案是:voidElemVec::foo(){ElemVec*This=this;BOOST_FO

c++ - 模板 :Name resolution:Point of instantiation: -->can any one tell some more examples for this statement?

这是来自ISOC++标准14.6.4.1实例化点的声明Forafunctiontemplatespecialization,amemberfunctiontemplatespecialization,oraspecializationforamemberfunctionorstaticdatamemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecializationandthecontextfromwhichi

c++ - 具有固定实现的虚函数不使用 (*this) 的大多数派生类

假设我有以下代码:structZ;structA{virtualvoidDo(Z&z)const;};structB:publicA{};structZ{voiduse(Aconst&a){}voiduse(Bconst&b){}};voidA::Do(Z&z)const{z.use(*this);}现在,当我调用B.do,this的类型是A,这是有道理的,因为do的实现在A中定义.有什么方法可以调用B.do使用use(Bconst&)无需为do复制粘贴相同的代码来自A进入B?在我的实际代码中,我有大约15个(并且还在不断增加)派生自某个基类的类,必须为do复制粘贴相同的代码似乎很浪费

c++ - 在基类中调用 shared_from_this() 时的 bad_weak_ptr

我有一个SuperParent类,一个Parent类(派生自SuperParent)并且都包含一个shared_ptr到一个Child类(它包含一个weak_ptr到一个SuperParent)。不幸的是,我在尝试设置Child的指针时遇到了bad_weak_ptr异常。代码如下:#include#include#include#includeusingnamespaceboost;classSuperParent;classChild{public:voidSetParent(shared_ptrparent){parent_=parent;}private:weak_ptrpare

c++ - 异常 : bad_weak_ptr while shared_from_this

当我这样做时出现异常:std::bad_weak_ptr->shared_from_this()templateclasspainter_record_t{.......private:std::shared_ptr_owner;}这里我想在构造函数中设置“问题”对象:templateclassstream_record_t:publicpainter_record_t{public:stream_record_t(std::shared_ptrowner):painter_record_t(owner){//...}}我有基类:classi_painter_t{public:virt

c++ - 返回 *this 和 this 之间的区别 - C++

ClassA{//Code...A&operator++(){//code..return____;}Aoperator++(){//code..return___;}我什么时候应该返回*this或this?我理解this是一个指针,*this是指针的取消引用,但是当函数需要通过引用或值来获取值时,我无法决定返回什么。 最佳答案 this在您的函数中属于A*类型,因此返回该类型不合适。*this在您的函数中属于A&类型,它可以绑定(bind)到A&或A。当重载前缀++运算符时,返回A&是函数的正常返回类型。

c++ - type_info 不考虑 cv 限定符 : is this right?

这段代码打印1是正确的行为还是g++4.5的怪癖?#include#includeusingnamespacestd;intmain(){structA{};cout我认为cv限定符的不同类型作为非常不同的类型受到威胁,即使较少的cv限定类型可以隐式转换为更多cv限定的类型。 最佳答案 typeid根据C++标准(摘自ISO/IEC14882:2003的§5.2.8)忽略cv限定符:Thetop-levelcv-qualifiersofthelvalueexpressionorthetype-idthatistheoperandof

c++ - free.c 抛出异常 "this program has stopped working"

当我使用VisualC++2010Express的调试器运行程序(server.exe)时,它运行完美,但是当我将它作为exe运行时它却没有;它崩溃并显示“Server.exe已停止工作”对话框。接下来我将exe重命名为“ServerInstaller.exe”并且它工作了,所以我认为这是一个权限错误,但它不适用于管理员模式下的“Server.exe”。然后我将VC++中的调试器附加到“Server.exe”程序,它在“free.c”中出现异常。这个文件中的代码是void__cdecl_free_base(void*pBlock){intretval=0;if(pBlock==NULL