s******s 发帖数: 505 | 1 C++ STL list 的实现:
为什么先写一个base类型,然后再从base继承出主要类型,比如list?
这个base似乎在任何别的地方都用不到。
这样做,从编程方法上有什么优越之处?谢谢! |
t****t 发帖数: 6806 | 2 maybe, in case you want to have any specialized implementation?
【在 s******s 的大作中提到】 : C++ STL list 的实现: : 为什么先写一个base类型,然后再从base继承出主要类型,比如list? : 这个base似乎在任何别的地方都用不到。 : 这样做,从编程方法上有什么优越之处?谢谢!
|
s******s 发帖数: 505 | 3
The header file noted that the purpose was to "split into" a
non-template base and a template type node. However, I fail
to see the point of doing this, since the STL list is only used and
known as a template class.
【在 t****t 的大作中提到】 : maybe, in case you want to have any specialized implementation?
|
t****t 发帖数: 6806 | 4 if the base class is non-template, then it makes perfect sense --- the non-
template part can be pre-compiled. i thought you are referring to libstdc++
(in which case the base class is also a template).
【在 s******s 的大作中提到】 : : The header file noted that the purpose was to "split into" a : non-template base and a template type node. However, I fail : to see the point of doing this, since the STL list is only used and : known as a template class.
|
X****r 发帖数: 3557 | 5 For each type as the parameter of this node class, the compiler
needs to generate a separate piece code for each instantiated class.
By moving common logic from the template node class to a
non-template base class, the corresponding code no longer get
duplicated, resulting smaller binaries.
【在 s******s 的大作中提到】 : : The header file noted that the purpose was to "split into" a : non-template base and a template type node. However, I fail : to see the point of doing this, since the STL list is only used and : known as a template class.
|
s******s 发帖数: 505 | 6
Thank you.
【在 X****r 的大作中提到】 : For each type as the parameter of this node class, the compiler : needs to generate a separate piece code for each instantiated class. : By moving common logic from the template node class to a : non-template base class, the corresponding code no longer get : duplicated, resulting smaller binaries.
|
s******s 发帖数: 505 | 7
+
Now I am confused. Sorry I don't know C++ well.
I thought STL was part of libstdc++.
【在 t****t 的大作中提到】 : if the base class is non-template, then it makes perfect sense --- the non- : template part can be pre-compiled. i thought you are referring to libstdc++ : (in which case the base class is also a template).
|
t****t 发帖数: 6806 | 8 libstdc++ is one particular (gcc's) implementation of STL
【在 s******s 的大作中提到】 : : + : Now I am confused. Sorry I don't know C++ well. : I thought STL was part of libstdc++.
|
|
s******s 发帖数: 505 | 9
I see, thank you.
【在 t****t 的大作中提到】 : libstdc++ is one particular (gcc's) implementation of STL
|