Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vector pointing to class

Status
Not open for further replies.

ARCITS

Programmer
Apr 4, 2002
99
GB
I've successfully managed to populate a vector with apointer to a class (well I think I have!)

How do I print out the contents with an iterator (see code below)

All I get printed are the memory locations in hex!


Thanks,


Andy.




vector <borrower*> BorrowerVector;
std::vector<int>::iterator it;

...........

for (int it=0;it !=BorrowerVector.size();it++)
cout << BorrowerVector[it]; <-------------------------------something wrong here I presume?

cout << &quot;size is - &quot; <<BorrowerVector.size()<<&quot; -&quot;; <---------------------------------------------works okay

 
BorrowerVector[it] is a pointer of your borrower object. To print its member, you have to list its member like,
cout << BorrowerVector[it]->myMember;
 
Thanks,

This appears to be working although I don't appear to have successfully populated the vector.
Can you please help?

My code is:

class borrower (int,string,string,int,int)


vector <borrower*> BorrowerVector;

BorrowerVector.push_back(borrower*(borrowerNo,borrowerName,emailAddress,maximumBooks,currentBooks));

I get the error ....

error C2275: 'borrower' : illegal use of this type as an expression


I also tried .....

BorrowerVector = new borrower(1,&quot;H&quot;,&quot;h&quot;,2,2);


Thanks!

 
you can do like this,
BorrowerVector.push_back(new borrower(1,&quot;H&quot;,&quot;h&quot;,2,2));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top