kludgy, - :
template <attribute x> class Base
{
public:
attribute get_x ( ) { return x; }
};
class Derived1 : public Base<SOME_ATTRIBUTE_1>
{
...
};
class Derived2 : public Base<SOME_ATTRIBUTE_2>
{
...
};
, / (, - . @visitor ).
, , ? :
class Base
{
public:
virtual attribute get_x ( ) = 0;
};
class Derived1 : public Base
{
public:
attribute get_x ( ) { return SOME_ATTRIBUTE_1; };
};
class Derived2 : public Base
{
public:
attribute get_x ( ) { return SOME_ATTRIBUTE_2; };
};
EDIT: , , :
template <attribute1 x, attribute2 y ...> class Base
{
public:
attribute get_x ( ) { return x; }
attribute get_y ( ) { return y; }
...
};
, , , :
class Base
{
public:
Base (attribute newX) : x(newX) { }
attribute get_x ( ) { return x; };
protected:
const attribute x;
};
class Derived1 : public Base
{
public:
Derived1 ( ) : Base(SOME_ATTRIBUTE_1) { }
};
class Derived2 : public Base
{
public:
Derived2 ( ) : Base(SOME_ATTRIBUTE_2) { }
};
Derived , . , , const, .