specialization

    2熱度

    3回答

    考慮這個代碼。 template<class T> class A { public: void f(){..} void h(){..} }; template<> class A<int> { public: void f(){// something different..} //void h(){..}

    0熱度

    3回答

    有人能告訴我如何刪除下面的重複專業化? #include <iostream> #include <fstream> #include <string> struct Thing { int a, b; void load (std::istream& is) {is >> std::skipws >> a >> b;} }; struct Object {

    4熱度

    3回答

    的數字操作我寫了一個函數做簡單的數學: def clamp(num: Double, min: Double, max: Double) = if (num < min) min else if (num > max) max else num 這是非常簡單的,直到我需要用長型相同的功能。我與類型參數化和專業化概括它: import Ordering.Implicits._ def

    0熱度

    1回答

    我已經工作了一組代表幾何形狀的各種比特模板類的,我意識到,我希望能夠專注不同的類來處理引用和指針例如方法 template<typename T> class rect{ // as in rectangle public: point<T> point1, point2; // Point simply contains two instances of type T .

    0熱度

    1回答

    我試圖實現一個非常基本的Vector3(Vec3)類。 我正在努力處理一個特例:Vec3<size_t>加上Vec3<int>。 如何爲這種情況製作模板專業化? 任何幫助,將不勝感激。 本 #include <array> #include <ostream> #include <vector> // #define Vec3f std::array<float, 3> // #defi

    2熱度

    2回答

    我上課是這樣的: template<class T> class A{ // lots of methods here Something get(); }; 我想Something get()成爲const Something &get()如果T是特定的類。 首先我試着用繼承來做,但它太亂了。 我可以這樣做,不需要專門整個class A,也不需要引入第二個模板。

    0熱度

    1回答

    我想從base1或base2繼承「派生」類。我想爲此使用模板專門化。我有以下 //base1 template<typename FT> class base1 { public: base1(FT m) {} }; //base2 template<typename FT> class base2 { public: base2(FT m)

    1熱度

    1回答

    我是使用C++模板的新手。 我需要爲我的項目編寫模板功能專業化。 對於不同類型的輸入它是一個簡單的Sum函數,它計算兩個迭代器之間的和。原始函數是通用的,因此接受模板參數。模板專業化是爲地圖編寫的。 #include <map> #include <string> template <typename T> double Sum(T &it_beg, T &it_end) { d

    3熱度

    1回答

    這在C法律++: template <int N> class A { void bar() {std::cout << N << '\n';} }; template<> void A<2>::bar() {std::cout << "Two\n";} // This is ok. 現在考慮這個類: template <int...> struct B; templat

    4熱度

    1回答

    假設我有一組類從單個超之傳承: class S{ ... }; class C1 : public S{ ... }; class C2 : public S{ ... }; 然後,假設我有一個模板方法: template<class T> void foo(T* instance); 我想靜態檢查foo從未被稱爲提供超類的實例,但僅被稱爲提供(具體)子類中的一個(例如明確地調用fo