Avatar billede jennemaan Nybegynder
08. januar 2010 - 10:10 Der er 1 kommentar

VS2008 STL Compiler Problem... (error C2784)

Hej folks,

jeg har følgende stump kode:

// Find item with id in table. If the item was not found, the function
    // the function returns the default value.
    //
    template <class Id_Type, class Val_Type>
    Val_Type find_value(const std::vector<ItemInfo<Id_Type, Val_Type> >& table,        // Table to search
                        const Id_Type& id,                                            // Value (item ID) to search for
                        const Val_Type& default_value)                                // Default value if the item was not found in table
    {
        std::vector<ItemInfo<Id_Type, Val_Type> >::const_iterator p = std::lower_bound(table.begin(), table.end(),id);

        if (p != table.end() && *p == id)
            return (*p).get_value();
        else
            return default_value;
    }


Koden bygger fint under VC7 (VS 2003), men fejler under VC9!

Her er output:

1>Compiling...
1>item_util.cpp
1>c:\program files\microsoft visual studio 9.0\vc\include\xutility(263) : error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const int'
1>        c:\program files\microsoft visual studio 9.0\vc\include\list(1310) : see declaration of 'std::operator <'
1>        c:\program files\microsoft visual studio 9.0\vc\include\algorithm(2262) : see reference to function template instantiation 'bool std::_Debug_lt<ItemUtil::ItemInfo<Id_Type,Val_Type>,_Ty>(const _Ty1 &,const _Ty2 &,const wchar_t *,unsigned int)' being compiled
1>        with
1>        [
1>            Id_Type=int,
1>            Val_Type=int,
1>            _Ty=int,
1>            _Ty1=ItemUtil::ItemInfo<int,int>,
1>            _Ty2=int
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\algorithm(2274) : see reference to function template instantiation '_FwdIt std::_Lower_bound<std::_Vector_const_iterator<_Ty,_Alloc>,int,__w64 int>(_FwdIt,_FwdIt,const int &,_Diff *)' being compiled
1>        with
1>        [
1>            _FwdIt=std::_Vector_const_iterator<ItemUtil::ItemInfo<int,int>,std::allocator<ItemUtil::ItemInfo<int,int>>>,
1>            _Ty=ItemUtil::ItemInfo<int,int>,
1>            _Alloc=std::allocator<ItemUtil::ItemInfo<int,int>>,
1>            _Diff=__w64 int
1>        ]
1>        d:\anylib2008\libraries\utility\item_util.cpp(63) : see reference to function template instantiation '_FwdIt std::lower_bound<std::_Vector_const_iterator<_Ty,_Alloc>,Id_Type>(_FwdIt,_FwdIt,const int &)' being compiled
1>        with
1>        [
1>            _FwdIt=std::_Vector_const_iterator<ItemUtil::ItemInfo<int,int>,std::allocator<ItemUtil::ItemInfo<int,int>>>,
1>            _Ty=ItemUtil::ItemInfo<int,int>,
1>            _Alloc=std::allocator<ItemUtil::ItemInfo<int,int>>,
1>            Id_Type=int
1>        ]
1>        d:\anylib2008\libraries\utility\item_util.cpp(98) : see reference to function template instantiation 'Val_Type ItemUtil::find_value<int,int>(const std::vector<_Ty> &,const Id_Type &,const Val_Type &)' being compiled
1>        with
1>        [
1>            Val_Type=int,
1>            _Ty=ItemUtil::ItemInfo<int,int>,
1>            Id_Type=int
1>        ]

Jeg har en mistanke om at det er en bug i VS2008... Det er meget sparsomt hvad jeg har kunne finde på MSDN og andre steder på nettet... Det ser ud som om at 'id' bliver opfattet som en __w64 int og ikke en int. Jeg bygger ren 32bit...


Nogen gode forslag til workarounds?

//Jens
Avatar billede bertelbrander Praktikant
10. januar 2010 - 01:03 #1
Jeg har ikke umiddelbart problemer med at compile det med VC9...
Jeg brugte denne dummy for ItemInfo:
template <typename id, typename val>
class ItemInfo
{
};

Det kunne tyde på at problemet er med ItemInfo, kan vi få at se hvordan den ser ud? Det ville være allerbedst om vi kunne få et komplet program der viser fejlen.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester