HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Nesting Structs

12-17-2009, 05:18 AM#1
thelifelessone
Why doesn't it work...?

Collapse JASS:
    struct Parent
        
        struct Child
        
        
        endstruct
        
    endstruct

Doesn't work.
12-17-2009, 11:09 AM#2
Hans_Maulwurf
You can only nest scopes. What are you trying to do? I think what you want to do is extend structs.
Collapse JASS:
struct Parent

endstruct

struct Child extends Parent

endstruct

http://www.wc3c.net/vexorian/jasshel...l#extendstruct
12-17-2009, 11:46 AM#3
Seshiro
No, he wants to nest, it's kind of a logical placement, just to show, that those to belong together.

It's not possible, because its not necessary, all profits you get with that you can earn by using privaze keyword and an intelligent Namiingconvention ...

Next time post in Triggers and Scripts or JH Thread :)

Greez
12-17-2009, 06:48 PM#4
thelifelessone
Bah. I need to be able to nest structs...
I'm trying to be able to do more OOP style programming, doing something like this; call Parent.Child.Method.

Is there any kind of work around for that?
12-17-2009, 10:45 PM#5
Vexorian
The work around is not doing it.

Composition is not part of vjass. I think that maybe if hell freezes , then melts and then freezes again I will make a good vJass compiler that allows nesting types and structs inside structs, but in jasshelper.exe it won't happen.
12-18-2009, 12:05 AM#6
TriggerHappy
It may not be exactly what you want.

Expand JASS:
12-18-2009, 02:42 AM#7
thelifelessone
Not quite...

What I want is this;

Collapse JASS:
//library...
    struct Parent
        struct Child
            static method Print takes nothing returns nothing
                call BJDebugMsg("Hai")
            endmethod
     endstruct

    function Init takes nothing returns nothing
        call Parent.Child.Print()
    endfunction
//endlibrary...

@Vexorian

I don't see what's wrong with it. It could really help with keeping code organized.
It doesn't really have to be nested classes. You could implement some kind of namespace style "container", which have the same effect (Parent.Child.Method)
12-18-2009, 02:51 AM#8
Vexorian
it is not wrong. It is just something I can't really add to jasshelper.exe's poor compiler ways. So if I ever code an actually good compiler it will allow it.
12-18-2009, 03:08 AM#9
TriggerHappy
That still would be very simple.

Expand JASS:
12-18-2009, 03:36 AM#10
thelifelessone
@ Vexorian

Ah.

@ TriggerHappy

Mind explaining exactly how that works?
12-18-2009, 04:23 AM#11
TriggerHappy
The struct Parent just has a pointer (named Child) to the ChildEx struct.
12-18-2009, 07:39 AM#12
thelifelessone
Alright, thanks. I'll try that tomorrow.
12-18-2009, 12:05 PM#13
Seshiro
Or you could use Delegates and use another struct that you use as the child ...