Search code examples
oopsdlvalasdl-ttf

unable to chain up to base constructor requiring arguments


public class Font : SDLTTF.Font {
    public Font (string _filename, int _size) {

    }

    public void draw () {

    }
}

That's my code. When I try to build it, I get:

Font.vala:4.5-4.15: error: unable to chain up to base constructor requiring arguments
    public Font (string _filename, int _size) {
    ^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

I thought I needed to override the constructor, so I tried to public override it, but now I get:

Font.vala:4.5-4.24: error: abstract, virtual, and override modifiers are not applicable to creation methods
    public override Font (string _filename, int _size) {
    ^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

Any ideas on how to fix this? I'm trying to inherit the SDLTTF.Font class.


Solution

  • Have you tried putting

    base(_filename, _size);
    

    in your constructor?

    EDIT: This worked for me. Note however that SDLTTF.Font is defined in the vapi as a compact class, meaning that when you derive it, you're only allowed to define new functions for your subclass, but no instance data (member variables, etc.). If you require this, I'd recommend you go with apmasell's suggestion and create a wrapper class deriving from (G)Object.