[Vala] Problems with HashMap/Dictionary



Hi!

I'm new to Vala and therefore I try to translate a Java-example to Vala. I
have translated the same Java-example to C# before with success. In this
example they use af HashMap (C#: Dictionary) and I know HashMap is a part of
LibGee. BUT, I cant make it work, the compiler keep on telling me an error:

My example:

public class ProductCatalog : GLib.Object {
        private var map;

        public ProductCatalog() {
            map = new HashMap<int, string>();

            // Sample data
            int id1 = 100;
            int id2 = 200;
            double price = 3;

            ProductDescription desc;
            desc = new ProductDescription(id1, price, "Product 1");
            descriptions.set(id1, desc);
            desc = new ProductDescription(id2, price, "Product 2");
            descriptions.set(id2, desc);
        }

        public ProductDescription get_product_description(int id) {
            return descriptions.get(id);
        }
}

The compiler gives me this error:

[kris odin Udvikling]$ valac --pkg gee-1.0 NextGen.vala
NextGen.vala:59.17-59.19: error: syntax error, statements outside blocks
allowed only in root namespace
        private var map;
                ^^^
Compilation failed: 1 error(s), 0 warning(s)


What is the problem here? I have Google'd like crazy but can't make it work
right.

// Kris


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