N
nw
Hi,
I'd like to have a set of classes which differ in that a static member
has a different value (obviously they share other functionality not
shown here). My currently proposed solution is this:
template<int _probability_id>
class MyClass {
public:
MyClass() {
}
static MyStaticMemberClass param;
...
};
Where I'd create different versions of the class all of which share
the static member with:
MyClass<0> type0Object; //shares static member with
object below
MyClass<0> anotherType0Object;
MyClass<1> type1Object; //different static member than
above, same as below.
MyClass<1> anotherType1Object;
I've not seen a solution like this before, and am wondering if it's a
valid and sensible thing to do? Is there a better solution that
someone can suggest?
One suggestion might be not to use a static member, however for this
application the overhead of the object or even a reference would be
significant (the objects are small and there are lots of them). In my
case I think the static member models the problem correctly as well
(all objects of a given type should have the same params).
Thanks for reading.
I'd like to have a set of classes which differ in that a static member
has a different value (obviously they share other functionality not
shown here). My currently proposed solution is this:
template<int _probability_id>
class MyClass {
public:
MyClass() {
}
static MyStaticMemberClass param;
...
};
Where I'd create different versions of the class all of which share
the static member with:
MyClass<0> type0Object; //shares static member with
object below
MyClass<0> anotherType0Object;
MyClass<1> type1Object; //different static member than
above, same as below.
MyClass<1> anotherType1Object;
I've not seen a solution like this before, and am wondering if it's a
valid and sensible thing to do? Is there a better solution that
someone can suggest?
One suggestion might be not to use a static member, however for this
application the overhead of the object or even a reference would be
significant (the objects are small and there are lots of them). In my
case I think the static member models the problem correctly as well
(all objects of a given type should have the same params).
Thanks for reading.