Re: [Vala] structs and lists



if you declare the XStruct as class, then it is possible:

using GLib;
class XStruct {
        public int integer;
        public SList items;
}

public class XClass {
        private List<XStruct> x_list;
        construct{
                this.x_list = null;
        }
        public void run (){
                for (int i=0;i<10;i++) {
                        XStruct x = new XStruct();
                        x.integer = i + 1;
                        this.x_list.append(x);
                }
        }
        static int main (string[] args) {
                XClass obj = new XClass();
                obj.run();
                foreach(XStruct xstr in obj.x_list) stdout.printf("%d
\n",xstr.integer);
                return 0;
        }
}
Regards, 
lariamat

Date: Mon, 04 Aug 2008 13:20:27 +0200
From: Roberto Majadas <roberto majadas openshine com>
Subject: Re: [Vala] structs and lists
To: vala-list <vala-list gnome org>
Message-ID: <1217848827 8557 5 camel kara>
Content-Type: text/plain; charset=utf-8

El lun, 04-08-2008 a las 09:44 +0200, Maciej Piechotka escribi?:
Roberto Majadas <roberto majadas openshine com> writes:


You cannot store structs in list.
1. Use class
2. Use pointers or other type of references
* How can i create a pointer to struct ?. Something like g_new0(XStruct,
1) Is it possible ?

telemaco


Regards






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]