小编god*_*lka的帖子

从extern C struct继承时成员的初始化

同一程序中混合使用C和C++代码时,给出了以下示例(此处略微缩写为相关部分).假设buf.h包含以下内容:

struct buf {
    char* data;
    unsigned count;
};

// some declarations of existing C functions for handling buf...
Run Code Online (Sandbox Code Playgroud)

然后建议使用

extern "C" {
  #include "buf.h"
}

class mybuf : public buf {
public:
    mybuf() : data(0), count(0) { }

    // add new methods here (e.g. wrappers for existing C functions)...
};
Run Code Online (Sandbox Code Playgroud)

为了在C++中使用带有附加功能的结构.

但是,这显然会产生以下错误:

error: class `mybuf' does not have any field named `data'
error: class `mybuf' does not have any field named `count'
Run Code Online (Sandbox Code Playgroud)

解释的原因在如何在派生类构造函数中初始化基类成员变量中进行了解释 …

c c++ inheritance struct init

17
推荐指数
1
解决办法
1029
查看次数

为什么类型下限会改变方差位置?

Scala语言规范(关于方差注释的第 4.5 节,第 44 页)

  • 类型参数的方差位置与封闭类型参数子句的方差位置相反。
  • 类型声明或类型参数下界的方差位置与类型声明或参数的方差位置相反。

使用上面的第一点,很容易看出(至少在形式上)

trait Covariant[+A] {
  def problematic[B <: A](x : B)
}
Run Code Online (Sandbox Code Playgroud)

产生错误消息

error: covariant type A occurs in contravariant position in type >: Nothing <: A of type B
       def problematic[B <: A](x : B)
Run Code Online (Sandbox Code Playgroud)

使用第一点和第二点很容易看出

trait Contravariant[-A] {
  def problematic[B >: A](x : B)
}
Run Code Online (Sandbox Code Playgroud)

产生错误消息

error: contravariant type A occurs in covariant position in type >: A <: Any of type B
             def problematic[B >: A](x : B)
Run Code Online (Sandbox Code Playgroud)

正如我所提到的,很容易从形式上(即遵循方差注释的规则)看出这些错误发生的原因。然而,我无法举出一个例子来说明这些限制的必要性。相反,很容易举出示例来说明为什么方法参数应该更改方差位置,请参见 …

scala generic-variance

5
推荐指数
1
解决办法
250
查看次数

将 deeplearning4j 模型导出到 Keras

我知道 deeplearning4j 可以从 Keras ( https://deeplearning4j.org/model-import-keras )导入模型,但我对相反的方式感兴趣。所以,

  • 有没有办法将 deeplearning4j 模型导出到 Keras?

这可以直接或通过某种方式转换使用 ModelSerializer https://deeplearning4j.org/modelpersistence存储的模型)?特别是,我对在 keras.js ( https://github.com/transcranial/keras-js )中使用训练有素的模型很感兴趣。

keras deeplearning4j

5
推荐指数
0
解决办法
435
查看次数

标签 统计

c ×1

c++ ×1

deeplearning4j ×1

generic-variance ×1

inheritance ×1

init ×1

keras ×1

scala ×1

struct ×1