I am trying to inherit STL vector class to create a new class on my own. It will use vector's base properties but i will add some new functions like sum or divide. The problem here is i am trying to implement that class also for different types. How can i use both inheritance and template at the same time ?
Below is my class body where i need some help.
//template <class T>
?
class NewVector<T> : public vector<T>{
//some constructors
};
Yes. Inheriting STL is not a good idea. I am aware of it. But lets say i am using this inheritance.
The problem i face here is building constructors.
I am calling constructor in main like this,
NewVector<int> v1(3);
but the problem is i can not create this v1 vector like STL vector does. When i try to debug get 0 for size and 0 for capacity. How will i edit the size and capacity in constructor ? I tried to do those but couldn't manage.
template <class T>
class NewVector : public vector<T>{
public:
NewVector(T n){
const ArithmeticVector<T> &v1(n);
cout<<v1.size()<<endl;
};
//some constructors
};
i see the size of v1 vector 0, but i want to see it 3 as i mentioned. A little help would be nice.
Here is the main file. i know i need to write some constructors but they need to work both int and double and also how will i tell my class to do them ?
using namespace std;
int main() {
NewVector<int> v1(3); // creating some objects
NewVector<int> v2(3); // vector elements are assigned randomly from 0 to 10
NewVector<double> v3(5);
NewVector<double> v4(5);
.....