I have this code:
struct All { public: All() {} ~All() {} };
template <typename T>
struct any : public All
{
public:
any() : All() {}
~any() {}
T value;
};
int main()
{
any<int>* a = new any<int>;
a->value = 55;
any<string>* b = new any<string>;
b->value = "Hello World !";
vector<All*> vec;
vec.push_back(a);
vec.push_back(b);
for (int i = 0; i < (int)vec.size(); i++) {
All* tmp = vec[i];
cout << tmp->value << endl; // Error appears here
}
return 0;
}
And the following error:
struct 'All' has no member named 'value'
And i don't know how to avoid this error. It seems that in the for loop tmp
is a All object, and All objects has no member named value.
They have no ways to access to child struct (any
) member variable from the All object tmp
to avoid this problem and have a fully fonctionnal generic vector ?