close

Compile time指的是compile進行檢查 , 編譯的階段 , 而run time則是指程式進行運作的phase.

Polymorphism 在運作時 , 也有分run time與compile time , 

Polymorphism is defined as one interface to control access to a general class of actions. 

There are two types of polymorphism one is compile time polymorphism and the other is run time polymorphism. 

Compile time polymorphism is functions and operators overloading. Runtime time polymorphism is done using inheritance and virtual functions. 

Polymorphism means that functions assume different forms at different times. In case of compile time it is called function overloading. 

For example, a program can consist of two functions where one can perform integer addition and other can perform addition of floating point numbers

but the name of the functions can be same such as add. 

The function add() is said to be overloaded. 

Two or more functions can have same name but their parameter list should be different either in terms of parameters or their data types. 

The functions which differ only in their return types cannot be overloaded. The compiler will select the right function depending on the type of parameters passed.

(也就是說 , 要選擇哪一個function , 是在compile time就決定好的 , 而要選擇哪個virtual function , 則是在程式運作時查閱virtual table才決定的.)

(在design patterns中 , cover的範圍大部分都是在於run time的部分)

ref : http://wiki.answers.com/Q/Difference_between_runtime_and_compile_time_polymorphism

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JerryCheng 的頭像
    JerryCheng

    KwCheng's blog

    JerryCheng 發表在 痞客邦 留言(0) 人氣()