在类中到达类函数
Reach class function in class?
本文关键字:类函数 更新时间:2023-10-16
我正在将代码从c++翻译成c#,现在我遇到了这个问题,所以我无法到达我必须到达的函数。
public struct TargetList_t
{
public float Distance;
public float[] AimbotAngle = new float[3];
public float[] aimbotAngle = new float[3];
public float[] myCoords = new float[3];
public float[] enemyCoords = new float[3];
public TargetList_t(float[] aimbotAngle, float[] myCoords, float[] enemyCoords)
{
Distance = Get3dDistance(myCoords[0], myCoords[1], myCoords[3], enemyCoords[0], enemyCoords[1], enemyCoords[2]);
AimbotAngle[0] = aimbotAngle[0];
AimbotAngle[1] = aimbotAngle[1];
AimbotAngle[2] = aimbotAngle[2];
}
};
这是我的班。
TargetList_t TargList;
我就是这么想的
在c++中可以通过
调用默认构造函数TargetList_t TargList;
在c#中,你总是想使用new
关键字:
// init your constructor parameters
float[] aimbotAngle = new float[1];
float[] myCoords = new float[1];
float[] enemyCoords = new float[1];
// call constructor
var targList = new TargetList_t(aimbotAngle , myCoords , enemyCoords);
指出:
您想要将
struct
更改为class
,因为这是(有争议的)它看起来像在c++中,你会添加后缀或前缀,说它是
type
,int
或其他什么,在c#中你通常不这样做,所以你的类名应该是TargetList
。此外,List
是.Net框架中一个众所周知的类,所以我希望这个类要么派生自它,要么从名称中删除List单词,如TargetList_t
=>Targets
使用公共属性代替公共字段
public float Distance;
=>public float Distance {get;set;}
相关文章:
- 如何通过派生类函数更改基类中的向量
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- 在类函数中初始化外部作用域变量
- c++ 在非类函数中使用类变量
- SDL_PollEvent() 无法捕获类函数内部SDL_QUIT?
- 从类成员函数到类 C 函数指针的转换
- 如何在模板类函数中分配结构值?
- 有没有办法将重载的类函数绑定到函数对象?
- 启动类函数作为失去引用的线程
- C++调用使用重写函数的父类函数
- 将值传递到另一个类函数在打印时为零
- 计算对类函数的所有调用次数
- 由于签名差异,调用了错误的子类函数
- 使用宏调用类函数
- 虚拟基类函数中派生类的大小
- 模板类/函数中的交叉前向声明
- 在C++中使用非静态类函数的函数
- 无法访问基类函数 C++
- 类函数返回到另一个类函数返回打印不同的值
- C++ 在外部使用嵌套结构实现类函数