作者:zvan | 来源:互联网 | 2023-09-13 10:50
看一些代码看到源码中模板的写法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| // DoublyLinkedListLink
template
class DoublyLinkedListLink {
public:
Element* next;
Element* previous;
};
// DoublyLinkedListMemberGetLink
template DoublyLinkedListLink Element::* LinkMember = &Element::fLink>
class DoublyLinkedListMemberGetLink {
private:
typedef DoublyLinkedListLink Link;
public:
inline Link* operator()(Element* element) const
{
return &(element->*LinkMember);
}
inline const Link* operator()(const Element* element) const
{
return &(element->*LinkMember);
}
}; |
这行代码:
1 2
| template DoublyLinkedListLink Element::* LinkMember = &Element::fLink> |
模板的第二个参数是什么用法,没搞懂什么意思..
没搞懂模板这种用法的目的是啥