Create instance of class

淺唱寂寞╮ 提交于 2019-12-25 18:04:08

问题


#include "2d/Vector2D.h"
#include <list>
#include "../../AbstTS.h"


class AbstRB;

class fTS: public AbstTS
{

public:

   fTS(AbstRB* owner);

   void       Update();
   void       closestBotStrategy();


};

class fGCBS
{

public:

    fGCBS(AbstRaven_Bot* owner);

    void       pickTarget();
 };


#endif

Above is my code, I want to get access to the pickTarget() from fGCBS class within the fTS class. I know I have to create an instance of this fGCBS but I dont know how to do this, any help is appreciated Thanking You


回答1:


To create an instance of a class, you need to call its constructor.




回答2:


One way would be to include an instance of fGCBS inside fTS.

class fTS: public AbstTS
{

public:

   fTS(AbstRaven_Bot* owner);

   void       Update();
   void       closestBotStrategy();
private:
   fGCBS my_fGCBS; // instance of fGCBS inside fTS
};

You would have to make a few other changes to your code for this to work. See if you can work them out.



来源:https://stackoverflow.com/questions/15882002/create-instance-of-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!