Hello everibody,
I'm new here and I don't know if this topic has already been discussed, but I've been googling it and found nothing, so here I am.
So, I have this class that gives access to a variable into a physics model. Since I don't know in advance which datatype will be associated with the variable, I made template get/set methods.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class ScalarVariable: public ModelVariable {
protected:
ScalarVariable( ExecutingModel& modelInstance, Model&
modelType, int nodeId );
public:
virtual ~ScalarVariable();
template <class T>
const T getValue() const;
template <class T>
void setValue( const T v );
};
|
Now I would like to have inherited classes that implement those template methods and specialize them if necessary, but I don't know how to write it with a proper synstax, e.g. if I write the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class IntegerVariable : public ScalarVariable {
friend class ModelVariableFactory;
protected:
IntegerVariable(
ExecutingModel& modelInstance,
Model& modelType,
int nodeId);
public:
virtual ~IntegerVariable();
const int getValue() const;
void setValue( const int v );
};
|
I am told by Eclipse that the method
const int getValue() const;
"Shadows" the getValue from the parent class, so I assume it will never use the code from the parent class.
I would like to have a general ModelVariable class that is used i.e. to handle the result of a factory, just like
|
ModelVariable& v = ModelVariableFactory::createVariable( *modelInstance, *modelType, nodeId );
|
while the factory really would create an instance of IntegerVariable or BooleanVariable or RealVariable, etc...
Is this possible? Is this realistic?
Thank you for your collaboration!!!
xB;)