I have templated class vector<typename T,size S>
(I have to use this instead of std::vector
). I would like to specify an alias which is in type ofvector<double,2>
, but I also need to count the amount of all created and all currently live objects of this. Here's fragment of my templated class:
template<typename T, size S>
class vector{
private:
T *_values;
public:
vector():
_values(new T[S]){
for(int i =0; i < S; i++)
_values[i] = T();
}
~vector(){
delete[] _values;
}
};
So I thought about creating class named vector2D
which inherits vector<double,2>
and with two additional static variables to count its amounts. But how to do that? How to invoke superclass constructor and destructor so that it only contains incrementation/decrementation of these two static variables? vector2D
is going to be used often in project I have to do. Maybe there is better solution?
P.S How to pretty initialize *_values
? I tried *_values = { 0 }
but it didn't work (of course assuming this is going to be a table of primitive types).