Is there any way to eliminate the explicit constructor call in Foo and somehow have Bar::len assigned to the size of any of Bar’s sub-classes?
class Bar
{
size_t len_;
Bar(size_t len) : len_(len) { }
};
class Foo : public Bar
{
Foo() : Bar(sizeof(Foo)) { }
};
You could use a “curiously recursive template” to inform the base class of the derived class’s type: