I want to compile a few haxe classes as a cpp library. The library contains only interfaces and classes implementing them. Since the library is going to be used by third-party integrators ignoring haxe heritage, types are decorated with @:nativeGen metadata.
As an example, consider the following code:
//MyInterface.hx
package foo;
@:nativeGen
interface MyInterface {
function bar(): Void;
}
//MyClass.hx
package foo;
@:nativeGen
class MyClass implements MyInterface {
public function new() {}
public function bar() {
trace("bar");
}
}
When I compile the code above with the command haxe foo.MyInterface foo.MyClass -cpp cpp, the compiler complains that
Error: In file included from ./src/foo/MyClass.cpp:5:
include/foo/MyClass.h:23:38: error: expected unqualified-id
class HXCPP_CLASS_ATTRIBUTES MyClass , public virtual foo::MyInterface
^
./src/foo/MyClass.cpp:15:6: error: incomplete type ‘foo::MyClass’ named in nested name specifier
void MyClass::bar(){
^~~~~~~~~
include/foo/MyClass.h:23:30: note: forward declaration of ‘foo::MyClass’
class HXCPP_CLASS_ATTRIBUTES MyClass , public virtual foo::MyInterface
^
./src/foo/MyClass.cpp:22:1: error: incomplete type ‘foo::MyClass’ named in nested name specifier
MyClass::MyClass(){
^~~~~~~~~
include/foo/MyClass.h:23:30: note: forward declaration of ‘foo::MyClass’
class HXCPP_CLASS_ATTRIBUTES MyClass , public virtual foo::MyInterface
The problem is in the malformed header MyClass.h.
//excerpt from MyClass.h
//NB the comma after MyClass should be a colon
class HXCPP_CLASS_ATTRIBUTES MyClass , public virtual foo::MyInterface
{
public:
MyClass();
void bar();
};
//excerpt from MyInterface.h
class HXCPP_CLASS_ATTRIBUTES MyInterface : public virtual ::hx::NativeInterface
{
public:
virtual void bar( )=0;
};
What is going wrong?
And why does the interface extend ::hx::NativeInterface? Is it possible to avoid the pollution of ::hx::NativeInterface?