Untitled

mail@pastecode.io avatar
unknown
plain_text
4 months ago
670 B
4
Indexable
struct Cfg {
    int x;
    int y;
};

class TestBase {
    Cfg cfg;
};


class Test : public TestBase {
    Test():
        work{cfg} // I need parsed cfg here
    {
          
    }

    Work work; // piece of work nvm
};

int parse_int_from_env(int default) {
   // if not in env, return default
   ...
}

class CfgParser {
    CfgParser(Test* test, const Cfg& defaults) {
        test->cfg.x = parse_int_from_env(defaults.x);
        test->cfg.y = parse_int_from_env(defaults.y);
    }
};

class ConcreteTest : public CfgParser, Test {
     ConcreteTest():
         CfgParser(this, {.x = 6, .y = 8}),
         Test()
     {}
};
Leave a Comment