I'm trying to access the object (called a Vector) pointed to by a pointer held in a vector container, but I can't seem to get to it.
Here are the important code snippets:
int main{
Vector<double>* test = new Vector<double>(randvec<double>());
test->save();
cout << Element::vectors[0];
return 0;
}
Where Vector
is a template class, randvec<T>()
returns a reference to a vector, save()
is
template <class T>
void Vector<T>::save()
{
vectors.push_back(this);
}
and vectors is static std::vector<Element*> vectors;
defined in Element.h, the base class of Vectors.
Am I going about this all wrong? I'm trying to contain all the elements of a derived class in a static data member of the base class by using a vector of pointers to the main class.
My output from main() might tell you what's going on – I get the pointer 0x1001000a0
. However, if I try to dereference that pointer, I get the following error:
error: no match for 'operator<<' in 'std::cout << * Element::vectors.
std::vector<_Tp, _Alloc>::operator[] [with _Tp = Element*, _Alloc = std::allocator<Element*>](0ul)'
Why can't I dereference this pointer?