好的 - 這可能是一個非常愚蠢的問題,但它一直困擾着我。功能參數多態性
是否有語言,其中
class Animal;
class Ape : public Animal
{...}
void doStuff(Animal* animalPtr)
{
cout << "doing animal stuff" << endl;
}
void doStuff(Ape* apePtr)
{
cout << "doing ape stuff" << endl;
}
Animal *ape = new Ape();
doStuff(ape);
會產生"doing ape stuff"
? (請使用C++語法與我聯繫) 爲了澄清,我希望「一個接受參數並根據參數類型對其進行操作的函數」。
它會有道理嗎?當然,作爲一名開發人員,您需要注意,因爲看起來像動物指針的實例可能實際上調用了Ape代碼,因爲在運行時它是一個指向的Ape實例。
常見LISP ...爲什麼這是一個驚喜(不!);) 謝謝你的術語澄清和維基百科鏈接! – msi 2010-01-30 21:30:20
我會第二個共同的lisp。 – Demosthenex 2010-01-30 23:59:03
把它分類爲深奧的幾乎令人傷心:-p – 2010-01-31 03:01:29