[计算机科学经

int main myclass1 mc1 myclass2 mc2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: pBoard { void open(); //譯註:隸屬於 CupBoard class template class Shelf; //譯註:隸屬於 CupBoard class template static double total_weight; //譯註:隸屬於 CupBoard class template ... }; 20 它們非常類似㆒般的 class members,然而有時候會被㆟誤稱為 member templates。 C++ Templates - The Complete Guide 8 98 基礎技術更深入(Fundamentals in Depth) template <int I> void CupBoard<I>::open() { ... } template <int I> class CupBoard<I>::Shelf { ... }; template <int I> double CupBoard<I>::total_weight = 0.0; 雖說這種參數化定義通常也被稱為 templates,但很多場合㆗這種稱謂並不合適。 8.1.1 虛擬成員函式 ( Virtual Member Functions ) Member function templates 不能宣告成 virtual。這個限制有其原因。通常虛擬函式呼叫機制使 用㆒個大小固定不變動的表格,其㆗每㆒筆條目(entry)記錄㆒個虛擬函式入口(entry point)。 然而直到整個程式編譯完成 編譯器才能知道有多少個 member function templates 需要被具現化。 , 因此,如果要支援 virtual member function templates,C++...
View Full Document

This note was uploaded on 08/25/2012 for the course EECS 101 taught by Professor Wre during the Fall '12 term at Beacon FL.

Ask a homework question - tutors are online