0

I currently have a vector of pointers, how would I cout the information at a particular pointer in the vector?

I am looking at how to deference the address stored in the vector.

1
  • Just like how you dereference anything else. Please post the code that's giving you trouble. Commented Jan 16, 2012 at 6:51

2 Answers 2

2
vector<MyType*> addressList; cout<<(*(addresssList[i])).Data ; //assuming Data is the content you want to output and you would like to output the content addressed by the `ith` element. 
Sign up to request clarification or add additional context in comments.

2 Comments

the "MyType" for me is a Class. the data that I was trying to access was a private variable. I defined a member function to return the information that I want, but my compiler says i need the this pointer "->". why is that
@Panda: If X is a class with some member function f(), and you have X * pX, then to call f() a valid syntax is pX->f(). (An alternative could be (*pX).f()).
0
std::vector<int*> ints; for ( auto cur = ints.begin(); cur != ints.end(); ++cur) { std::cout << (*(*cur)) << "\n"; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.