interface I
{
    void setX(int x);
    int getX();
}

class C : I
{
    int x, y;

    void setX(int x) { this.x = x; }
    int getX()       { return x;   }
    void setY(int y) { this.y = y  }
    int getY()       { return y;   }
}


void main()
{
auto obj = new C; // Want new C to instantiate obj with static type I.
    obj.setX(3);      // Ok, sets x to 3.
    obj.getY();       // Error, not specified in the interface.
}

- Is it possible to enforce, from within the class, a certain static interface type or ancestor type when instantiating with new? If so, how is it done? - Also, is it possible for a class to implement multiple interfaces and choose static type among them when instantiated, based on static class state or arguments passed to the constructor?

Reply via email to