Vector of pointers

Hi guys

Can somebody please help me to understand how to make and use a vector of pointers, I am aware that a vector of pointers is used to point to objects of a class, but how do I use one exactly :S. For example, keeping customer info in the vector so that it can be used with a class member object. I know I haven't got a example and I apologise, but if someone could give me an idea on how to create and use one, it would be hugely appreciated.

Thanks :)
what exactly is the problem?... to declare a vector of pointers ?... or how to use it? (use it like u use an array if u want to access it)
How to use one I think I know how to declare:
vector<class*> name
1
2
3
std::vector<CustomerInfo*> database;

database.push_back( new CustomerInfo( /* params */ ) );
std::string strData = "One";
//Declaration for C++ vector
std:: vector <std::string> str_Vector;
str_Vector.push_back(strData);
strData = "Two";
str_Vector.push_back(strData);
strData = "Three";
str_Vector.push_back(strData);
strData = "Four";
str_Vector.push_back(strData);

Using our normal logic for accessing elements stored in C++ Vector:

for(int i=0;i < str_Vector.size(); i++)
{
std::string strd = str_Vector.at(i);
cout<<strd.c_str()<<endl;
}

Using C++ vector iterator provided by STL:
std::vector<std::string>::iterator itVectorData;
for(itVectorData = str_Vector.begin(); itVectorData != str_Vector.end(); itVectorData++)
{
std::string strD = *(itVectorData);
}
Removing elements from C++ vector:
str_Vector.erase(str_Vector.begin()+1,str_Vector.begin()+2);
http://cplusplus.com/reference/stl/vector/


the interesting parts are in the
Element access:
section (especially operator[])

and push_back() & pop_back() but i suggest u to read nearly all of them... its interesting
Topic archived. No new replies allowed.