Sign in to follow this  
Phoresis

C++ Vectors

Recommended Posts

I want to declare a pointer to an object stored inside a vector, but it won't let me.
TableComponent *t;
for(vector<TableComponent>::iterator iter = items.begin(); iter != items.end(); iter++) 
{
  if (test == iter->getId())
  {
    t = iter;
  }
}
What am I doing wrong?

Share this post


Link to post
Share on other sites
The types TableComponent* and vector<TableComponent>::iterator are not compatible. Just use the iterator type instead - it can do everything a pointer can.

vector<TableComponent>::iterator t;

for(vector<TableComponent>::iterator iter = items.begin(); iter != items.end(); iter++)
{
if (test == iter->getId())
{
t = iter;
}
}


HTH

Share this post


Link to post
Share on other sites
Quote:
Original post by Simian Man
The types TableComponent* and vector<TableComponent>::iterator are not compatible. Just use the iterator type instead - it can do everything a pointer can.

vector<TableComponent>::iterator t;

for(vector<TableComponent>::iterator iter = items.begin(); iter != items.end(); iter++)
{
if (test == iter->getId())
{
t = iter;
}
}


HTH


Ah right, thanks, that makes sense now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this