假设我在 F# 中有以下接口:
type InterfaceA =
abstract Magic : InterfaceA -> InterfaceA
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现这样的接口?当我尝试这样做时:
type MyTypeA = {x:int} with
interface InterfaceA with
member self.Magic another =
{x=self.x+another.x}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
This expression was expected to have type 'InterfaceA' but here has type 'MyTypeA'
免责声明:我是 Qt 的新手。
假设我们有一个从函数返回的字节数组innerFunc,稍后在另一个函数中使用outerFunc。
QByteArray innerFunc(){
QProcess ls;
ls.start("ls", QStringList() << "-1");
return ls.readAll();
}
void outerFunc(){
QByteArray gotcha = innerFunc();
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
在 vanilla c++ 中,我希望readAll函数返回一个稍后需要删除的指针。在 Qt 中,这个函数返回该类的一个实例QByteArray,所以我想它不应该在innerFunc的范围之外访问。
如果是这样,我应该如何正确地将数据传输到外部函数?应该复制QByteArray *tmp = new QByteArray还是没有必要?