相关疑难解决方法(0)

C++成员函数指针

我正在用C++做一个小游戏,我发现了类成员函数指针.我不知道让它们以正确的方式工作,但这是我的尝试.

// A struct where the function pointer will be stored for the call
// By the way, is there a way to do the same thing with classes ?
// or are structs still fine in C++ ? (Feels like using char instead of string)
typedef struct      s_dEntitySpawn
{
  std::string       name;
  void          (dEntity::*ptr)();
} t_dEntitySpawn;

// Filling the struct, if the entity's classname is "actor_basicnpc",
// then I would like to do a call like ent->spawnBasicNPC
t_dEntitySpawn      dEntitySpawns[] = …
Run Code Online (Sandbox Code Playgroud)

c++ pointers class pointer-to-member

3
推荐指数
1
解决办法
1089
查看次数

标签 统计

c++ ×1

class ×1

pointer-to-member ×1

pointers ×1