翻译 C++德尔福课程
我正在将一些 C++ 代码翻译为 Delphi,并且有一些抽象类需要翻译。这些类用作参数/返回类型等,我的问题是,像这样的 C++ 类层次结构是否
class Thing {
virtual void blah() = 0;
};
class Thing2 : public Thing {
virtual bool asdf(Thing*) = 0;
};
可以在 Delphi 中重写为:
Thing = class
procedure blah; virtual;
end;
Thing2 = class(Thing)
function asdf(Thing) : Boolean; virtual;
end;
Delphi 代码可以调用采用 C++ Thing*s 和东西的 C++ 函数,并且C++ 代码可以调用采用 Delphi Things 等的 Delphi 函数。所以基本上,如果进行上述翻译,C++ Thing2* 是否等于 Delphi Thing2,其中 Delphi 可以调用它的方法等?
I am translating some C++ code to Delphi and there are some abstract classes that need to be translated. These classes are used as parameter/return types, etc, and my question is if a C++ class hierarchy such as this:
class Thing {
virtual void blah() = 0;
};
class Thing2 : public Thing {
virtual bool asdf(Thing*) = 0;
};
can be rewritten in Delphi as:
Thing = class
procedure blah; virtual;
end;
Thing2 = class(Thing)
function asdf(Thing) : Boolean; virtual;
end;
And the Delphi code can call C++ functions that take C++ Thing*s and stuff, and C++ code can call Delphi functions that take Delphi Things, etc. So basically, if the above translation is made, will a C++ Thing2* equal a Delphi Thing2 where Delphi can call it's methods, etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不完全是。在 C++ 中,将方法标记为
= 0
表示它是抽象方法。在Delphi中,要获得相同的效果,必须将其标记为virtual;抽象;
,而不仅仅是虚拟;。另外,在 Delphi 中,如果您将类成员声明直接放在类名下,则默认情况下它将被声明为
published
,这意味着它是公共的,并且会为其生成 RTTI。这可能不是您的意图,因此首先放置可见性范围声明(private、protected
或public
):Not quite. In C++, marking a method as
= 0
means it's an abstract method. In Delphi, to get the same effect, you have to mark it asvirtual; abstract;
, not just asvirtual;
.Also, in Delphi, if you place a class member declaration immediately under the class name, it'll be declared by default as
published
, which means it's public plus RTTI is generated for it. That's probably not your intention, so put a visibility scope declaration (private, protected
orpublic
) first: