2013-07-31 39 views
0

所以我做了某種數據庫,像這樣boost_multi_index:的boost :: multi_index錯誤「模板參數‘X’是無效的」

#include <boost\multi_index_container.hpp> 
#include <boost\multi_index\ordered_index.hpp> 
#include <boost\multi_index\member.hpp> 
using namespace boost::multi_index; 
using namespace std; 

struct list_entry{ 
    int id; 
    string name; 
    string* data; 
}; 

typedef multi_index_container<list_entry, 
    indexed_by< 
     ordered_unique< tag<int>, member<list_entry, int, &list_entry::id>>,    // unique id 
     ordered_unique< tag<string>, member<list_entry, string, &list_entry::name>>,  // unique name 
     ordered_non_unique< tag<string*>, member<list_entry, string*, &list_entry::data>> // some data associated with the id/name 
    > 
>table; 

class Database 
{ 
    private:  
     table music, names; 
     typedef table::index<int>::type list_id; 
     typedef table::index<string>::type list_string; 

    //some more code here 
}; 

,並與Visual Studio編譯罰款2010

然而我想在與MinGW的代碼:: Blocks的轉換我的項目,好像他不是那麼滿意了,這是編譯日誌:

.\source\db.h|19|error: template argument 3 is invalid| 
.\source\db.h|15|error: template argument 2 is invalid| 
.\source\db.h|15|error: template argument 1 is invalid| 
.\source\db.h|14|error: template argument 2 is invalid| 
.\source\db.h|13|warning: 'typedef' was ignored in this declaration [enabled by default]| 
.\source\db.h|24|error: 'table' does not name a type| 
.\source\db.h|25|error: 'table' does not name a type| 
.\source\db.h|26|error: 'table' does not name a type| 
C:\Program Files\boost_1_54_0\boost\system\error_code.hpp|222|warning: 'boost::system::posix_category' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\system\error_code.hpp|223|warning: 'boost::system::errno_ecat' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\system\error_code.hpp|224|warning: 'boost::system::native_ecat' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\asio\error.hpp|244|warning: 'boost::asio::error::system_category' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\asio\error.hpp|246|warning: 'boost::asio::error::netdb_category' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\asio\error.hpp|248|warning: 'boost::asio::error::addrinfo_category' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\asio\error.hpp|250|warning: 'boost::asio::error::misc_category' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\asio\ssl\error.hpp|34|warning: 'boost::asio::error::ssl_category' defined but not used [-Wunused-variable]| 
C:\Program Files\boost_1_54_0\boost\asio\detail\winsock_init.hpp|116|warning: 'boost::asio::detail::winsock_init_instance' defined but not used [-Wunused-variable]| 
||=== Build finished: 7 errors, 10 warnings (0 minutes, 15 seconds) ===| 

我完全一無所知,因爲錯誤是沒有任何更多SPE比這個更重要,我也找不到任何相關的問題。

所以我希望有人可以在這裏給我一個答案,如果需要更多信息,我會在之後進行編輯。

回答

0

我能夠通過使用BOOST_MULTI_INDEX_MEMBER這樣來解決這個問題:

typedef multi_index_container<list_entry, 
    indexed_by< 
     ordered_unique< tag<int>, BOOST_MULTI_INDEX_MEMBER(list_entry, int, id)>, 
     ordered_unique< tag<string>, BOOST_MULTI_INDEX_MEMBER(list_entry, string, name)>, 
     ordered_non_unique< tag<string*>, BOOST_MULTI_INDEX_MEMBER(list_entry, string*, data)> 
    > 
>table; 
+0

這就奇怪了......我懷疑有一個命名衝突問題與'member',你可以嘗試明確資格與': :boost :: multi_index :: member' –

+0

我以前試過用'boost :: multi_index ::'(不帶前導'::')顯式限定所有內容,並刪除'using namespace'行,但問題仍然存在。然而,在做了一些更廣泛的搜索之後,我發現了BOOST_MULTI_INDEX_MEMBER,它似乎在編寫跨平臺代碼時使用,所以我決定嘗試一下(就像我說的那樣)。 – user2047610

+0

那麼,'BOOST_MULTI_INDEX_MEMBER'會產生變化的唯一情況是,如果你的編譯器太舊以至於有'BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS'缺陷宏打開。你可以檢查嗎? –