COMMUNITY

Cant call functions from a c++ class?

I have a class “externed” from c++ in haxe. I wanna be able to run a function from C++.
I dont want the function to be static. Here is the code:

Haxe file:

@:include("test.cpp")

extern class CppClass {
    public function new():Void;
    public function sayHello():Void;
}

class Main {
    static public function main() {
        var testObject = new CppClass();
        testObject.sayHello();
    }
}

test.cpp (the thing i import at the top)

#include <iostream>

class CppClass
{
public:
    CppClass(){
        std::cout << "constructed class\n";
    }

    void sayHello(){
        std::cout << "Hello\n";
    }
};

It runs perfectly fine and says “constructed class” when i dont call the function but when i do i get this error.

Error: ./src/Main.cpp: In static member function ‘static void Main_obj::main()’:
./src/Main.cpp:33:25: error: base operand of ‘->’ has non-pointer type ‘CppClass’
33 | HXLINE( 18) testObject->CppClass::sayHello();

The expected out put is it to run the hello world function in the cpp file…

PLZ HELP OMG :((( PLZ!!!

Add the @:structAccess attribute to your extern class.