Hi Jake,

I don't think it is possible to create an instance of the inner class type from outside of the outer class. I believe we don't allow those symbols to be referenced outside of the scope of the outer class - this is similar to how we treat nested functions. However, you can get an instance of the inner class to live outside of the outer class by having the outer class return an instance and storing that result, and you can call methods on the inner class.

Unfortunately a quick check through our most likely test directory didn't reveal an exact candidate matching this scenario. The closest I could find is this future (read: test that doesn't quite work today) example, https://github.com/chapel-lang/chapel/blob/master/test/classes/vass/nested-class-with-user-defined-constructor-1.chpl

A simple modification to this program will cause it to behave "properly" or close to your purpose - merely add an "outer" arg to the inner constructor, or remove the user-defined inner constructor entirely.

That program stores an instance of the inner class, but it uses a method on the outer class to generate it, so that the inner class always knows what outer instance it points to. Note that if you try to declare the type of "i", you get a type resolution failure.

Hope that helps,
Lydia Duncan

On 08/28/2016 10:09 AM, Caswell, Jacob wrote:

My apologies, I found the answer to the access question in the language specification. However, I couldn't find an example for creating an instance of an inner class outside of the outside class. Is it called just as:


class outside {

    ...

    class inside {

        ...

    }

}


var out_class : outside;

var in_class : outside.inside;


Or is there another form of declaration and initialization?


Thank you very much,

Jake



------------------------------------------------------------------------
*From:* Caswell, Jacob <[email protected]>
*Sent:* Sunday, August 28, 2016 10:36 AM
*To:* [email protected]
*Subject:* [EXTERNAL] Nested classes in Chapel

Hello all,


I found the following tutorial that says classes in Chapel are similar to classes in Java. Does this mean that Chapel supports nested classes as well? I've been reworking some of my code to use object oriented structures to help facilitate task parallelism in a multilocale execution. The idea being that I could create an instance of the task, which needs both fields and methods specific to the executing locale, in a reusable way. However, I've been having some issues with using nested classes in my code.


In Chapel, is it possible to create an instance of an inner class, either within a method from the outer class or outside of both of the classes? And if so, what access will the inner class have? Can it return variables from its outer class? Is there documentation for this functionality that I missed?


Thank you very much,

Jake



------------------------------------------------------------------------------


_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

------------------------------------------------------------------------------
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to