Create instance of class

2019-09-20 12:17发布

问题:

#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.