![]() |
| ||
| Genreic Double Linked List Using Templates Generic Double Linked List /* These are generic Functions for a Generic List If there is any critique about this code plz tell me about it to be careful in the next time i write any code . |
| ||
| Re: Genreic Double Linked List Using Templates You wrote a bunch of C-style unsafe functions instead of a good C++ class List with comfortable and safe interface. Look at the class std::list as a model. Now these templates look like a steam-engine with microcontrolled whistle... |
| ||
| Re: Genreic Double Linked List Using Templates Quote:
BTW thanx for your advice. |
| ||
| Re: Genreic Double Linked List Using Templates I see. I think it's not the best problem area to try generic functions. You are trying to declare a family of related functions implemented some generic data structure. But it's exactly a class notion. Now your efforts demonstrated a disparity of a goal and tools. When we need generic functions? We want a generic unit of functionality - for example, generic sort array operation... Apropos, don't use by value parameters in program cases as in following code: ... append(node<type>** l,type elem) {No need in argument copying, use references:... append(node<type>** l,const type& elem) {Yet another remark(s): print_l function requires operator << for template argument class. Why? There are lots of data classes without such operator but now you can't use them with your functions package. Avoid such names as print_l: simply look at print_l and print_1 (different;) ) names... |
| ||
| Re: Genreic Double Linked List Using Templates Mr ArkM i'm very thankful for your interaction with me . Could u plz explain your purpose cuz i tried it and it went to infinite loop while displaying random numbers (or maybe the addresses) and why we pass the reference of the element while u know in the structure up there contains a variable of type X not a pointer of type X to receive the address ?. Plz Explain your point Mr.ArkM . :$ |
| ||
| Re: Genreic Double Linked List Using Templates Try to insert val at pos 4 without insert val at pos 2..Is it work?.. |
| ||
| Re: Genreic Double Linked List Using Templates Quote:
|
| ||
| Re: Genreic Double Linked List Using Templates This is the modified function template <class type> void append(node<type>** l,const type& elem) and this is the test in main int main(int argc, char** argv) |
| ||
| Re: Genreic Double Linked List Using Templates Well, this code prints "Invalid position" then exit (it's a very bad solution: after exit() automatic class variables destructors are not called). You don't use modified append function. Moreover, passed by reference data argument can't raise new problems at all... I have no time to debug your code from the beginning. Please, make a proper test plan, prepare test cases then ask help with the serious problems brief and clear description. It's so simply to destruct your list via improper calls of these low-level functions. May this package debugging troubles help you to understand that all these low level operations must be incapsulated in the well-designed class ;)... |
| All times are GMT -4. The time now is 2:21 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC