overload-resolution

    6熱度

    1回答

    隨着克++ 3.4和4.7我觀察到以下奇怪的行爲: 如果用戶定義的轉換是必要的函數模板不匹配,其中,一個普通的功能會。 我無法在C++ 98標準中找到相應的規則。 g ++是否正確,(如我所假設的)?或者它是一個錯誤? template <class T> int x(auto_ptr_ref<T> p) { return 1; } // this would match /*

    1熱度

    1回答

    我有一些 - 可能真的很愚蠢 - 關於重載分辨率的問題。 假設有一個受限制的通用方法Greet接受T類型的參數person,該參數必須來自Person。這Greet方法然後在另一個類中調用一些非泛型方法,將person作爲參數傳遞。該非泛型方法有幾個重載 - 對於基類和派生類。爲什麼總是調用基類的重載? 實施例: public static class Test { public st

    3熱度

    3回答

    #include <iostream> #include <string> void fnc (const std::string&) { std::cout<<1; } void fnc (std::string&&) { std::cout<<2; } int main() { fnc ("abc"); } 所有的編譯器選擇std::

    3熱度

    1回答

    我被功能重載解析帶密封蓋在夫特3. 例如混淆,在代碼: func f<T>(_ a: T) { print("Wide") } func f(_ a: (Int)->(Int)) { print("Narrow") } f({(a: Int) -> Int in return a + 1}) 我期望Narrow,不Wide,要被打印到控制檯。任何人都可以解釋爲什

    1熱度

    2回答

    在斯卡拉,爲什麼會允許超載? class log { def LogInfo(m: String, properties: Map[String, String]): Unit = { println(m) } def LogInfo(m: String, properties: Map[String, String], c: UUID = null):

    8熱度

    1回答

    這不是關於Windows窗體的,它只是用於「背景」。 我玩弄圍繞Windows窗體,當我在一個AddRange得到一個錯誤,需要投ToolStripMenuItem到ToolStripItem 一個MenuStrip.Items,但我已經有一個Form.Controls這之前並不需要強制轉換的AddRange。 一個小實驗後,我設法發現,當有多個超載對於AddRange所以我想驗證我的想法發生了錯

    2熱度

    3回答

    我目前正在爲我的一些類編寫序列化程序。 我創建了一組靜態方法具有以下簽名 public static string serialize(int val); public static string serialize(string val); public static string serialize(float val); public static string serialize(M

    2熱度

    1回答

    當我們通過一(多)派生類模板函數期待基類什麼是模板實例規則?例如: #include <iostream> template <int x> struct C {}; struct D : C<0>, C<1> {}; template <int x> void f (const C<x> &y) { std::cout << x << "\n"; } int main()

    -1熱度

    1回答

    時會被調用,其被重載用於用戶定義類型X如下自由函數foo(C作爲一個庫類型的主叫foo): template <typename C> void foo(C&, const X&) {...} 我能夠確定在編譯時是否存在用於特定類型X過載: template <typename... Args> auto foo_exists(int) -> decltype(std::bind<void

    8熱度

    1回答

    我無法理解爲什麼下列導致曖昧電話: #include <iostream> // generic version f(X, Y) template <class X, class Y> void f(X x, Y y) { std::cout << "generic" << std::endl; } // overload version template <class