简体   繁体   English

如何使用Haxe的“包装”声明?

[英]How to use Haxe “package” declarations?

Why package declarations like in below two files couses compiler errors, and how to achieve having my declared package on both files (with Main included)? 为什么像下面两个文件中那样的程序包声明会导致编译器错误,以及如何在两个文件中都包含我声明的程序包(包括Main )?

File Main.hx 文件Main.hx

package foo;
class Main {
    function new() {
        var x:A = new A();
    }

    static function main() {
        var main = new Main();
    }
}

File A.hx 文件A.hx

package foo;
class A {
    public function new() {
        trace('Hi.');   
    }
}

Try structuring your project like this: 尝试像这样构造项目:

[project root]
    /source
        /foo
            Main.hx
            A.hx

Then call Haxe with these arguments, with [project root] as the current working directory: 然后使用以下参数调用Haxe,并以[project root]作为当前工作目录:

haxe -cp source --interp -main foo.Main

The name of source doesn't really matter, it could be src or Source , but the directory the .hx files are placed in needs to match their package ( foo ). source的名称并不重要,可以是srcSource ,但是.hx文件所在的目录需要与其包( foo )相匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM