boost-any

    1熱度

    1回答

    我想在地圖中保存提升信號對象(關聯:信號名稱→信號對象)。信號簽名是不同的,所以第二種類型的地圖應該是boost :: any。 map<string, any> mSignalAssociation; 問題是如何在不定義新信號簽名類型的情況下存儲對象? typedef boost::signals2::signal<void (int KeyCode)> sigKeyPressed; mS

    0熱度

    1回答

    鑄造 我用任何類型的值打包一些類到ptr_map。 class EventManager { ptr_map<string, any> mSomeMap; public: typedef signals2::signal<void (int someSignature)> KeyEvent; EventManager() { m

    0熱度

    3回答

    我使用ptr_map來存儲不同類型的指針。 boost::ptr_map<string, any> someMap; 我存儲在那裏的一些模板類對象: someMap.insert("1", new SomeClass<int>()); someMap.insert("2", new SomeClass<float>()); 現在我想從地圖中獲取值。下面是引用一個例子: template<

    4熱度

    1回答

    我正在使用boost :: any有多態類型,我需要能夠將一個對象轉換爲它的基類型。 class A { public: int x; virtual int foo()= 0; }; class B : public A { public: int foo() { return x + 1; } };

    12熱度

    9回答

    我有一個地圖std::map<std::string, boost::any>,它來自boost::program_options包。現在我想打印地圖的內容: for(po::variables_map::const_iterator it = vm.begin(); it != vm.end(); ++it) { std::cerr << it->first << ": " << it

    0熱度

    1回答

    我試圖從list<boost::any> l l.remove(class_type); 刪除類對象我試着寫這樣的事情作爲一個成員函數 bool operator == (const class_type &a) const //not sure about the arguments { //return bool value } 你會如何寫重載函數從的std ::列表中刪

    1熱度

    2回答

    給定一組函數,例如: template<class A1> Void Go(A1 a); template<class A1, class A2> Void Go(A1 a1, A2 a2); template<class A1, class A2, class A3> Void Go(A1 a1, A2 a2, A3 a3); 是否可以接受某種變體類型的數組並給定其內容,激發

    2熱度

    3回答

    假設我有一個類型爲list<boost::any>的列表,其中有一些類型是未知的。現在假設我想對多態的列表中的元素應用一些操作。在這種情況下,請考慮+運算符。假設我知道該列表將始終包含一組支持operator +的同類對象,並且我想要將列表的每個元素之間的運算符+(在一種意義上的「總和」)應用到新的boost ::任何。事情是這樣的: boost::any sum(list<boost::any>

    4熱度

    3回答

    我正在使用boost::any來存儲指針,並想知道是否有 提取多態數據類型的方法。 下面是一個理想情況下我想要做的簡單示例,但目前不起作用。 struct A {}; struct B : A {}; int main() { boost::any a; a = new B(); boost::any_cast< A* >(a); } 這失敗了,因爲a