C++ Newbie question
-
hi all Can you please help me with this basic pb I have a structure struct NameAndCode { char fName[10] ; long fCode ; } ; after an sql query I get a list of NameAndCode NameAndCode **list How can I add a new NameAndCode in the end of the list ? :doh: :doh: Thanks for help
-
hi all Can you please help me with this basic pb I have a structure struct NameAndCode { char fName[10] ; long fCode ; } ; after an sql query I get a list of NameAndCode NameAndCode **list How can I add a new NameAndCode in the end of the list ? :doh: :doh: Thanks for help
do you use any STL containers by any chance ? also, why do you use a pointer of pointer if you have a simple "list" ? see if you can use
std::vector<NameAndCode>
instead[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
hi all Can you please help me with this basic pb I have a structure struct NameAndCode { char fName[10] ; long fCode ; } ; after an sql query I get a list of NameAndCode NameAndCode **list How can I add a new NameAndCode in the end of the list ? :doh: :doh: Thanks for help
Can you tell us what "list" are you using? -Saurabh
-
Can you tell us what "list" are you using? -Saurabh
-
do you use any STL containers by any chance ? also, why do you use a pointer of pointer if you have a simple "list" ? see if you can use
std::vector<NameAndCode>
instead[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Hi STL seems more familar for me but does it mean, it's impossible to add a structure at the end of a pointer of pointer ? hope you see my pb thx for help
there are several points I don't get. first, you didn't answered my previous question : why do you use a pointer of pointer if you have a simple "list" ? also, if you're familiar with STL, why not using it ? and to answer your question (which I don't think is the good design to follow though), no it's impossible to litteraly "add a structure at the end of a pointer to pointer". for that, you'll have to allocate a new area with a size of "last array"+1, then copy every old pointers address into the new "list", and add the pointer to your new struct at the end of the list. at last, don't forget to delete the old array. but I still think you'd better use a vector. the std::vector::push_back() function will do this transparently for you...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]