IIRC objects are in the future. However, I'm currently writing C++ and
keep finding something annoying that I'd like to be able to do easily.

I have objects with attributes, such as

class Foo {
    ...
    std::size_t spare;
    std::size_t allocate;
    std::size_t min_readline;

and then I have lots of constructors

  public:
    Foo (...) ...  spare(0), allocate (4096), min_readline(80) ...

    Foo (..., ...) ...  spare(0), allocate (4096), min_readline(80) ...

    Foo (..., ..., ...) ...  spare(0), allocate (4096), min_readline(80) ...


As far as I can tell the only way to say "spare should default to 0" is
to spell it out in each and every constructor. I'd like to write


class Foo {
    ...
    std::size_t spare = 0
    std::size_t allocate = 4096
    std::size_t min_readline = 80

and have the compiler know that if I specify a member initialiser in my
my constructor, then that should be used, otherwise to default to using
the value I say. (To avoid the inevitable search/replace if I want to
change that value)

I can't figure out if there is a way to do this in C++ (the above syntax
isn't legal) and I'd like perl6 objects to make this sort of thing easy.

Nicholas Clark

Reply via email to