2013-07-31 41 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'缺陷宏打开。你可以检查吗? –