【发布时间】:2019-02-28 00:01:29
【问题描述】:
我需要帮助将这个 C++ 头文件翻译成 Delphi。
它是一个回调函数原型,还有一些内联函数(我不清楚它们为什么会存在,因为它们似乎没有被使用)。
源 .h 代码:
// This file defines 'myStreamWriter_t' a function pointer type.
// The user of the C API need to specify a callback of above type which
// will be called on xxx_print(...) with the formatted data.
// For C++ API, a default callback is specified which writes data to
// the stream specified in xxx::print
typedef int(*myStreamWriter_t)(const char* p1,
int p2,
void *p3);
上面很简单:应该翻译成Delphi,如下:
type
myStreamWriter_t = function(const p1:Pchar;
p2:integer;
p3:pointer):integer;
现在,还有一些我不知道如何翻译的东西:
源 .h 代码:
#include <ostream>
namespace ns1 {
namespace ns2 {
inline int OstreamWriter(const char *p1, int p2, void *p3);
struct StreamProxyOstream {
static int writeToStream(const char* p1, int p2, void *p3);
// Format, to the specified 'p3' stream, which must be a pointer to a
// 'std::ostream', the specified 'p2' bytes length of the specified 'p1' data.
};
inline
int StreamProxyOstream::writeToStream(const char *p1,
int p2,
void *p3)
{
reinterpret_cast<std::ostream*>(p3)->write(p1, p2);
return 0;
}
inline
int OstreamWriter(const char *p1, int p2, void *p3)
{
return StreamProxyOstream::writeToStream(p1, p2, p3);
}
} // close namespace ns2
} // close namespace ns1
...上面的Delphi怎么翻译??
非常感谢!
【问题讨论】: