specialization

    6熱度

    2回答

    我想編寫一個數學矢量模板。我有一個接受類型和大小作爲模板參數的類,有很多數學運算方法。 現在我想寫的專業化,其中矢量< 3>例如有x,y,z作爲分別引用data [0..3]的成員。 問題是,我不知道如何創建一個專門化,它繼承了默認模板中的所有內容,而無需創建基類或將所有內容寫入兩次。 什麼是最有效的方法來做到這一點? template<class Type, size_t Size> clas

    2熱度

    4回答

    我的問題是下面 template<class T> MyClass { MyClass(/* Lots of parameters with no problem */, const T& min = 0, const T& max = std::numeric_limits<T>::max()); set(/* Lots of parameters with no prob

    4熱度

    3回答

    可能重複: partial specialization of function template 我不能在任何地方找到我的問題的解決方案,因爲如果我用我想出的關鍵字搜索與會給我適合不同問題的解決方案。我明白這個問題以前一定要問,只是找不到解決辦法。 假設我有一個函數模板: template<class any> print(any value); 我可以專注像這樣對我們說int: templ

    0熱度

    1回答

    所以我遇到了功能模板部分專用化的問題。我選擇在這裏描述的解決方案:Question 現在我有這樣的: #include <vector> #include <iostream> template <typename T> struct helper { static void print(T value) { std::cout << value; } }; template

    1熱度

    1回答

    我想寫一個定點運算類,其中點位置和基本類型是模板 template <int P, typename T> class basic_fixedpoint{ //stuff }; 我也想公開一個模板隱構造函數,然後專門爲各種類型 //inside basic_fixedpoint template <typename U> basic_fixedpoint(co

    2熱度

    1回答

    我玩弄模板專業化和SFINAE。 至於下面的例子中,事情似乎很容易: template <class T> void Do(T t, typename std::enable_if<std::is_integral<T>::value >::type* = 0) { cout << "is integer" << endl; } templat

    11熱度

    4回答

    我想根據類模板參數來確定調用哪個版本的成員函數。我曾經嘗試這樣做: #include <iostream> #include <type_traits> template<typename T> struct Point { void MyFunction(typename std::enable_if<std::is_same<T, int>::value, T >::typ

    0熱度

    1回答

    假設一個模板我有這樣的模板: template<class T, int a, int b> class Foo 我上面的模板對焦炭的部分特殊版本: template<int a, int b> class Foo<char, a, b> 我還哪有專注於上述模板,比如a = 1?

    1熱度

    3回答

    我要實現一個非成員函數isHomogenous(三重三重)爲模板類定義爲: template <typename T1, typename T2, typename T3> class Triple { public: Triple() { } Triple(const T1 &a, const T2 &b, const T3 &c) : a(a), b

    2熱度

    3回答

    我有一個關於模板類的問題。 例如,藉此類 template<class TBase> class CTemplateInherit : public TBase { public: virtual void DoNonSpecializedWork(); virtual void DoTemplateWork(); virtual ~CTemplateInher