I am working on a system that will take a stream of data and sort it into various output streams. The objects that pass through the system are all of the same type, but it is necessary that the end user of the system can make certain changes to the type passed though the system by subclassing the class of the data objects.
Inspired by the accepted answer to this question Base enum class inheritance, my data object class will provide a set of constant values. Users will be able to subclass the data class and add new static consts int. For example:
class Base /* provided as part of system */
{
public:
static const int OUTPUT_STREAM_TYPE_1 = 0;
static const int OUTPUT_STREAM_TYPE_2 = 1;
int mSomeMemberVariables;
bool SomeMethods(int stream_type);
}
class Derived : public Base /* provided by user */
{
public:
static const int OUTPUT_STREAM_TYPE_3 = 2;
}
My question is, can my users safely cast Derived to Base for passing through the system, and then back to Derived once they receive them in whichever stream the system selected? I suspect yes, because statics are not contained in instances, and so instances of Base and Derived should be identical. But is this guaranteed to work?