Hi!
let's say i want to have a member variable for a pointer to std::vector but i do not want to specify what type of variable it stores. I want to access only those functions that are independant of it's actual generic type. is this possible with c++? something like this:
class Foo{
public:
void setVec(std::vector* someVec){
myVec = someVec;
};
int getSize(){
return myVec.size();
};
private:
std::vector* myVec;
};
int main(){
Foo foo;
vector<int> vec1;
vector<float> vec2;
foo.setVec(&vec1);
cout<<foo.getSize();
foo.setVec(&vec2);
cout<<foo.getSize();
}
note: i do not want to template Foo and i want to use only a single instance of Foo with vectors of different type.
of course - if I could alter the class vector then i could create an untemplated baseclass
class Ivector{
virtual int size()=0;
};
and then make the
class vector<T> : public IVector...
inherit from Ivector. but what do I do if i can't alter the class in question and the templated class does not have such an untemplated baseclass?
thanks!