首页 > 解决方案 > 这是D错误吗?(无法访问私有模板参数)

问题描述

handled_record.d

module handled_record;

template CObjects(alias destructor) {
    void f() {
        destructor();
    }
}

world.d

module world;

import handled_record;

private void free() { }

alias objects = CObjects!(free);

编译:

$ dmd -c *.d
handled_record.d(5): Error: function world.free is not accessible from module handled_record
world.d(7): Error: template instance `handled_record.CObjects!(free)` error instantiating

如果我删除private关键字,错误就会消失。

它是编译器错误吗?(据我了解,传递给模板的别名符号应该可以被模板访问,因为它是显式传递给模板的,即使它是私有的。)

标签: compiler-errorsdprivate

解决方案


推荐阅读