E
Ek.H
Hey,
I have a templated class (code follows) that I wish to put
into a vector, however I wish to put multiple of the class
into the vector and all might vary in what type they
represent.
Is there a way for me to to this without using multiple
vectors for each type of the class ?
(PS: I'm new to programming)
Code Snippet:
#include <iostream>
#include <vector>
template <typename T> class keeper {
private:
T& value;
public:
keeper(T& in_value) : value(in_value) {
}
~keeper () {
}
};
int main () {
float my_float_value = 0.1f;
int my_int_value = 129;
keeper<float> my_float(my_float_value);
keeper<int> my_int(my_int_value);
/* this one needs to be changed */
std::vector< keeper > my_keepers;
return(0);
}
I have a templated class (code follows) that I wish to put
into a vector, however I wish to put multiple of the class
into the vector and all might vary in what type they
represent.
Is there a way for me to to this without using multiple
vectors for each type of the class ?
(PS: I'm new to programming)
Code Snippet:
#include <iostream>
#include <vector>
template <typename T> class keeper {
private:
T& value;
public:
keeper(T& in_value) : value(in_value) {
}
~keeper () {
}
};
int main () {
float my_float_value = 0.1f;
int my_int_value = 129;
keeper<float> my_float(my_float_value);
keeper<int> my_int(my_int_value);
/* this one needs to be changed */
std::vector< keeper > my_keepers;
return(0);
}