如何从客户端代码中定义的类中调用客户端代码方法?
例如,我有一个内存读取类,可以从某个地址的进程内存中读取值.我还有用于管理从内存中读取的数据类型的类(我正在阅读游戏中的'对象'.在'客户端代码'中我计算内存中该对象的'基地址',然后初始化我的'对象类'使用一个构造函数,它以'基地址'作为参数.这个基类应该能够通过方法告诉我关于该对象的事情,因为对象知道离基地址有多远,某个值是,例如'健康')
我尝试使用这样的代码,它给了我一个错误.'ObjectManager'是可以从内存中读取值的类.
class ObjectManager : Memory
{
LocalCharacter LocalPlayer = new LocalCharacter(this);
// other things omitted
}
// Error: Keyword 'this' is not available in the current context
Run Code Online (Sandbox Code Playgroud)
出于绝望:
class ObjectManager : Memory
{
LocalCharacter LocalPlayer = new LocalCharacter(ObjectManager);
// other things omitted
}
// Error: Keyword 'this' is not available in the current context
Run Code Online (Sandbox Code Playgroud)
但无济于事.做这个的最好方式是什么?
ljs*_*ljs 10
如何在构造函数中引用'this': -
class ObjectManager : Memory
{
ObjectManager()
{
LocalPlayer = new LocalCharacter(this);
}
LocalCharacter LocalPlayer;
// other things omitted
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4145 次 |
最近记录: |