0

I have an .obj parser, code is:

class Model {
public:
    List *coords;
    List *tcoords;
    List *normals;
    List *faces;

    Model() {
        coords=new List();
        tcoords=new List();
        normals=new List();
        faces=new List();
    }

    ~Model() {
        delete(coords);
        delete(tcoords);
        delete(normals);
        delete(faces);
    }

};

this is a model file parser tool, which is parse a big file. The List is a linkedlist. (String array, char*)

How can I return this class to Java from C++? I know how can return a simple String Array with NewObjectArray, but what is the way to return a Class?

Thanks, Leslie

2 Answers 2

1

Typically, you create a peer class on the Java side that holds a pointer to the class in a long variable.

Jim S.

Sign up to request clarification or add additional context in comments.

1 Comment

And you ensure that Java code does not use that pointer after the C++ class instance has been deleted -- for example, by managing the lifetime of the C++ class instance from the Java side (not through finalizers).
0

In C++ code you can instantiate any Java object by calling env->NewObject() method and passing appropriate constructor signature to it. Constructors have special name <init>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.