本文发表在 rolia.net 枫下论坛- In general, why need MyList?
1、数据封装到哪里去了?Mylist中应当加private的listsize,Alist × firstnode, Alist * lastnode等,自己处理链表长度,首指针、尾指针等信息
- ?? You didn't understand the code. There are a list of items, not list of Alists
2、Mylist的构造和析构函数呢?IoCreateAList不应该是成员函数,而应该对应成传入参数为const Alist & 的构造函数
- "const Alist &" makes no sense here, a copy constructor? a const reference?? why?
- To have "IoCreateAList" in Alist (we don't need MyList) is not an bad idea, just need to make it static, otherwise where do you want to put it? remember, "要封装!"
3、C++中的new不应该检查是否为空,对应应该进行例外处理try-catch-throw,因为new根本不会返回null,分配失败,系统抛出例外,你要处理
- Unfortuntely, not all C++ compilers are 100% ISO compliant, for example, previous version of VC++, so having that check may not be as bad as you think.
4、IoAppendItem改为Append(const Alist & node); 要封装!
- Read code first, he wants to append an "Item" to the list not another "Alist"
5、IoInsertItem改为Insert(const Alist &node, Iterator itr); 如果对Iterator是什么不知道的话,在学习STL前,至少也应该写成nsert(const Alist &node, int pos);
- You use const on AList (should be Item), why not using it on iterator?, if you 对const and const_iterator是什么不知道的话,在学习C++ and STL前, hehe ... ;-).
- And see #7
6、add, remove, delete见上
- And see #7
7、IoGetItem改为Iterator setto(int pos);
- So, your logic is: "pos" ==> "iterator" ===> "item". Why just simply "pos" ===> "item". Iterator makes no sense to users of the class, all they want is "Item" and all they know is "pos". So why did you suggest giving them back iterator? Remember "要封装!". ( Note: People might want iterators if they need to use stl algoritms/functors/predictors...).
8、IoListSize改为const int size(){ return listsize;}
- FUNNY! Does it make any sense to return a CONST INT?? Though it's not wrong, but just very funny, don't you know return code is put in EAX and in 286 when int is 16bits the EAX happened to have 16bits, so now since 386 we've have 4bytes there and a int heppens to only need 4 bytes in a 32bit system?? People might want "int size() CONST { return listsize;}", people might what "const int AConstant = xxx', but I can tell you, you little junior programmer ;-), no one needs "const int" return code, well, no one cares, cos when it gets compiled, trust me, your code 100% sure will be ignored by compiler as a line of junk code.
9、IoClearList改写为析构函数
10、IoFreeList改写为Alist的析构函数
- Please read code, again.
Here is my comments for you : "...................不多说了,说句不客气的话,你是一个知道 a little bit C++语法的 junior 程序员" haha. Please don't take this seriously, just for fun.更多精彩文章及讨论,请光临枫下论坛 rolia.net
1、数据封装到哪里去了?Mylist中应当加private的listsize,Alist × firstnode, Alist * lastnode等,自己处理链表长度,首指针、尾指针等信息
- ?? You didn't understand the code. There are a list of items, not list of Alists
2、Mylist的构造和析构函数呢?IoCreateAList不应该是成员函数,而应该对应成传入参数为const Alist & 的构造函数
- "const Alist &" makes no sense here, a copy constructor? a const reference?? why?
- To have "IoCreateAList" in Alist (we don't need MyList) is not an bad idea, just need to make it static, otherwise where do you want to put it? remember, "要封装!"
3、C++中的new不应该检查是否为空,对应应该进行例外处理try-catch-throw,因为new根本不会返回null,分配失败,系统抛出例外,你要处理
- Unfortuntely, not all C++ compilers are 100% ISO compliant, for example, previous version of VC++, so having that check may not be as bad as you think.
4、IoAppendItem改为Append(const Alist & node); 要封装!
- Read code first, he wants to append an "Item" to the list not another "Alist"
5、IoInsertItem改为Insert(const Alist &node, Iterator itr); 如果对Iterator是什么不知道的话,在学习STL前,至少也应该写成nsert(const Alist &node, int pos);
- You use const on AList (should be Item), why not using it on iterator?, if you 对const and const_iterator是什么不知道的话,在学习C++ and STL前, hehe ... ;-).
- And see #7
6、add, remove, delete见上
- And see #7
7、IoGetItem改为Iterator setto(int pos);
- So, your logic is: "pos" ==> "iterator" ===> "item". Why just simply "pos" ===> "item". Iterator makes no sense to users of the class, all they want is "Item" and all they know is "pos". So why did you suggest giving them back iterator? Remember "要封装!". ( Note: People might want iterators if they need to use stl algoritms/functors/predictors...).
8、IoListSize改为const int size(){ return listsize;}
- FUNNY! Does it make any sense to return a CONST INT?? Though it's not wrong, but just very funny, don't you know return code is put in EAX and in 286 when int is 16bits the EAX happened to have 16bits, so now since 386 we've have 4bytes there and a int heppens to only need 4 bytes in a 32bit system?? People might want "int size() CONST { return listsize;}", people might what "const int AConstant = xxx', but I can tell you, you little junior programmer ;-), no one needs "const int" return code, well, no one cares, cos when it gets compiled, trust me, your code 100% sure will be ignored by compiler as a line of junk code.
9、IoClearList改写为析构函数
10、IoFreeList改写为Alist的析构函数
- Please read code, again.
Here is my comments for you : "...................不多说了,说句不客气的话,你是一个知道 a little bit C++语法的 junior 程序员" haha. Please don't take this seriously, just for fun.更多精彩文章及讨论,请光临枫下论坛 rolia.net