正在加载图片...
Handle a type parameter(cont.) Consider Initialization template< typename valtype template typename valtype inline BTNode<valtype> inline btnode<valtype> BTNode(const valtype& val) BTNode(const valtype& val) m Val m iCnt=1 Child=rchild=0 Child= rchild=o } Recommended //will call default constructor of matrix //will call copy constructor of Matrix /to m Val before entering the body, //to m Val only once //then the copy assignment operator BTNode <int> btni(20); //No difference in performance BINode<Matrix> btnm(mat8X8): /Handle a type parameter (cont.) ◼ Consider Initialization template < typename valtype > inline BTNode<valtype>:: BTNode(const valtype& val) :m_Val(val) { m_iCnt = 1; lchild = rchild = 0; }; template < typename valtype > inline BTNode<valtype>:: BTNode(const valtype& val) { m_Val = val; m_iCnt = 1; lchild = rchild = 0; }; BTNode<int> btni(20); //No difference in performance BTNode<Matrix> btnm(mat8x8); //…? //will call copy constructor of Matrix //to m_Val only once //will call default constructor of Matrix //to m_Val before entering the body, //then the copy assignment operator Recommended
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有