Re: [Vala] Classes as objects?



For the record, I still haven't figure out how to do this, but I do have a work-around. I made a "blank" object for each class I wanted to deal with, and this call the method on that object. In the process, I discovered another problem with my initial plan: Apparently you can't override static methods in Vala. Now that I have objects, I can change the static methods to be standard object methods, even though they don't do anything to or with the object in question.

This system works, but it feel very hackish. I'd happily accept advice for better way to handle this situation.

Thanks,
Robert


On 06/03/2012 01:57 PM, Robert Schroll wrote:
Hi all,

Is it possible to treat classes as objects in Vala, similar to how
delegates let you treat methods as objects?

What I'm trying to do is go through a list of classes and call a static
method on each. In Python, I could do this as

for klass in [Class1, Class2]:
klass.static_method()

In Vala, when I try

foreach (var klass in {Class1, Class2})
klass.static_method();

I get "error: initializer list used for unknown type" at the open brace.

If it helps, all of the classes are descended from the same superclass.

Thanks in advance,
Robert



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