gpt4 book ai didi

c++ - 将 C++ 结构移植到 Delphi

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:08:33 25 4
gpt4 key购买 nike

首先,让我向您展示结构:

struct HPOLY
{
HPOLY() : m_nWorldIndex(0xFFFFFFFF), m_nPolyIndex(0xFFFFFFFF) {}
HPOLY(__int32 nWorldIndex, __int32 nPolyIndex) : m_nWorldIndex(nWorldIndex), m_nPolyIndex(nPolyIndex) {}
HPOLY(const HPOLY& hPoly) : m_nWorldIndex(hPoly.m_nWorldIndex), m_nPolyIndex(hPoly.m_nPolyIndex) {}

HPOLY &operator=(const HPOLY &hOther)
{
m_nWorldIndex = hOther.m_nWorldIndex;
m_nPolyIndex = hOther.m_nPolyIndex;
return *this;
}

bool operator==(const HPOLY &hOther) const
{
return (m_nWorldIndex == hOther.m_nWorldIndex) && (m_nPolyIndex == hOther.m_nPolyIndex);
}
bool operator!=(const HPOLY &hOther) const
{
return (m_nWorldIndex != hOther.m_nWorldIndex) || (m_nPolyIndex != hOther.m_nPolyIndex);
}
__int32 m_nPolyIndex, m_nWorldIndex;
};

有些事情我不明白。

结构体中重复的 HPOLY 是什么意思?以及如何将结构转录为 Delphi 代码?

感谢您的帮助。

最佳答案

结构中 HPOLY 的重复是该类型的构造函数的定义。在 Delphi 中,复制构造函数(C++ 中的第三个,它根据同一类型的另一个实例构造该类型的实例)在 Delphi 中不是必需的。双参数构造函数允许您为两个字段指定初始值。默认的零参数构造函数将字段的值设置为 -1,但 Delphi 不允许在记录上使用这样的构造函数。

该结构的下一部分是赋值运算符。 Delphi 自动提供记录。接下来是比较运算符,用于比较类型是否相等。当您使用 = 时,编译器将调用它们和 <> HPoly 上的运营商值(value)观。

type
HPoly = record
m_nPolyIndex, m_nWorldIndex: Integer;
constructor Create(nWorldIndex, nPolyIndex: Integer);
class operator Equal(const a: HPoly; const b: HPoly): Boolean;
class operator NotEqual(const a: HPoly; const b: HPoly): Boolean;
end;

constructor HPoly.Create(nWorldIndex, nPolyIndex: Integer);
begin
m_nPolyIndex := nPolyIndex;
m_nWorldIndex := nWorldIndex;
end;

class operator HPoly.Equal(const a, b: HPoly): Boolean;
begin
Result := (a.m_nPolyIndex = b.m_nPolyIndex)
and (a.m_nWorldIndex = b.m_nWorldIndex);
end;

class operator HPoly.NotEqual(const a, b: HPoly): Boolean;
begin
Result := (a.m_nPolyIndex <> b.m_nPolyIndex)
or (a.m_nWorldIndex <> b.m_nWorldIndex);
end;

关于c++ - 将 C++ 结构移植到 Delphi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4934963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com