static-polymorphism

    1熱度

    1回答

    我有以下簡單的代碼: #include <iostream> #include <vector> template <class Derived> struct Base { Base() { static_cast<Derived*>(this)->foo(); } std::vector<int> m_ints; }; st

    -1熱度

    2回答

    從來就得到了一個超Token一些子像Knight,King,Queen等 我需要一個隨機Token類型,因此我把這個方法: public Class randomTokenType(){ Class[] classes ={ Bishop.class, King.class, Knight.class, Pawn.class, Queen.class, Rook.class };

    1熱度

    3回答

    這是我試圖實現的簡化示例。因此,它可能看起來有點傻,但忍受着我。比方說,我有 template<int i> class Class1{ foo(){cout<<"j is divisible by i, so we will hang out"<<endl;} } ,並具有固定int j變量class2:要麼通過這樣一個int或有一個成員變量模板化。我想class2情況下只能夠調用fo

    1熱度

    1回答

    下面的代碼,從大多複製 http://accord-framework.net/docs/html/T_Accord_MachineLearning_VectorMachines_Learning_SequentialMinimalOptimization.htm 工作正常。 module SVMModule open Accord.MachineLearning open Accord.M

    3熱度

    1回答

    我有幾種類型的使用策略,即 template <typename PolicyA, typename PolicyB> class BaseType : PolicyA, PolicyB {}; struct MyPolicyA {}; struct MyPolicyB {}; struct OtherPolicyB {}; using SpecializedTypeX = Bas

    -1熱度

    2回答

    我想知道如何在不使用虛函數的情況下在C++中聲明接口。經過一番互聯網搜索我放在一起此解決方案: #include <type_traits> using namespace std; // Definition of a type trait to check if a class defines a member function "bool foo(bool)" template<t

    7熱度

    2回答

    我想使用CRTP來實現編譯時多態,並且想要強制派生類來實現函數。 當前的實現是這樣的。 template <class Derived> struct base { void f() { static_cast<Derived*>(this)->f(); } }; struct derived : base<derived> { void f()

    5熱度

    1回答

    我想構建一個通用算法。到目前爲止,我已經實現了這個使用類層次結構和指針,如下面的例子: struct Base{ virtual double fn(double x){return 0;} }; class Derived : public Base{ double A; public: Derived(double a) : A(a) {} do

    0熱度

    1回答

    我目前正在將數據存儲庫集成到我的應用程序中。我需要能夠爲我的單元測試嘲笑這個數據存儲(這是I/O密集型),因此創建了該庫接口的包裝。 不幸的是,在它的接口中,這個庫將迭代器作爲指針而不是值返回,因爲它們在運行時是多態的。 我的問題是,由於多態性我加入的層,似乎不可避免地添加是多態運行時的迭代器,因此招致間接的一個新的水平和一些動態分配... // Library code class LibIt

    1熱度

    1回答

    考慮以下2種擴展方法 public static string getIDPropertyName(this object value) { return "ID"; } public static string getIDPropertyName<IDType>(this EntityRestIdentityDescriber<IDType> entityIdentityDes