:omg:What he said.
mcoloney
Posts
-
so... -
Passing a vector of pointersDave, Thank you again. You're a master.
-
Passing a vector of pointersDave, thanks again for your quick and informative reply. Allow me to include better code representation: My function definition is:
void addPhoneRecord(string& name, string& address, string& phone, PhoneRecord* records[]) { Name* nameEntry = new Name(); nameEntry->set_name(name); Address* addressEntry = new Address(); addressEntry->set_address(address); PhoneRecord* phoneEntry = new PhoneRecord(nameEntry, addressEntry); phoneEntry->set_phoneNumber(phone); records.push_back(phoneEntry); }
When I call it from main I'm using:addPhoneRecord(name, address, phone, &phonerecs.back());
All of the setting functions and the like work like they should, and properly. The error I'm getting is: error C2228: left of '.push_back' must have class/struct/union type If I comment out therecords.push_back(phoneEntry);
it compiles fine, but I get the standard WinXP error report problem. Any suggestions? Thanks again. -
Passing a vector of pointersFriends, I have a vector of pointers:
vector< PhoneRecord*> phonerecs(MAX);
I want to pass this vector to a function so I can add things to it outside of main(). The function declartion is:void addPhoneRecord(PhoneRecord* records[]);
and call it from main() using something like:addPhoneRecord(phonerecs);
The error I'm getting is: error C2664: 'addPhoneRecord' : cannot convert parameter 1 from 'class std::vector<class PhoneRecord *,class std::allocator<class PhoneRecord *> >' to 'class PhoneRecord *[]' I understand I'm not passing this correctly... I'm sure this is a somewhat easy solution, but I can't seem to pinpoint it. Thanks in advance! -
operator != for iteratorsDave, thank you so much for your help!
-
operator != for iteratorsSorry about that. It's reposted. Ignore the space after the < and before PhoneRecord.. it was making it a smiley.
-
operator != for iteratorsFriends, I'm trying to create a function so I can print the conents of a STL list from main(). It looks like:
void TraverseAndDisplay(list< PhoneRecord>::iterator& itor, const list< PhoneRecord>& l) { while (itor != l.end()) { cout << *itor++ << " "; } cout << endl; }
Unfortunately, because PhoneRecord is not a primitive data type (it's my own class), the default operator != won't work. The exact error I'm getting is: error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::list<class PhoneRecord,class std::allocator<class PhoneRecord> >::const_iterator' (or there is no acceptable conversion) Obviously I need to overload the != to work. I don't know how to overload the != operator to work for iterators in this case? Thanks in advance for your help!