• Advertisement
Sign in to follow this  

More STL error message woes (Solved)

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason std::map is refusing to take a std::string as the key. Seeing as this is one of my first experiments with std::map I was wondering if anyone had any ideas as to why (I know it's going to be a really dumb problem, but I'm even dumber). Maker.h:
template <class Object> class Maker
{

public:

    //--- Ctors/Dtors ---//

    virtual ~Maker ()
    {
        s_registry.clear ();
    }

    //--- Functions ---//

    static Object* NewObject (const std::string &object_name)
    {
        MakerPtr maker = s_registry.find (object_name)->second;

        return maker->MakeObject ();
    }

protected:

    //--- Ctors/Dtors ---//

    Maker (const std::string &object_name)
    {
        s_registry.insert (std::make_pair (object_name, this));
    }

    //--- Functions ---//

    virtual Object *MakeObject () const = 0;

private:

    //--- Types ---//

    typedef Maker <Object> *MakerPtr;
    typedef std::map <std::string, MakerPtr> MakerMap;

    //--- Variables ---//

    static MakerMap s_registry;
};


EntityMaker.h
class EntityMaker : public Maker <Entity>
{

protected:

    //--- Ctors/Dtors ---//

    EntityMaker (const std::string &object_name) : Maker <Entity> (object_name)
    {
    }
};


The Error Messages: EntityMaker.cpp c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1170) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(138) : while compiling class-template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const' with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(67) : see reference to class template instantiation 'std::less<_Ty>' being compiled with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(23) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled with [ _Kty=std::string, _Ty=Maker<Entity>::MakerPtr , _Pr=std::less<std::string>, _Alloc=std::allocator<std::pair<const std::string,Maker<Entity>::MakerPtr >>, _Mfl=false ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(65) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled with [ _Traits=std::_Tmap_traits<std::string,Maker<Entity>::MakerPtr ,std::less<std::string>,std::allocator<std::pair<const std::string,Maker<Entity>::MakerPtr >>,false> ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(87) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled with [ _Traits=std::_Tmap_traits<std::string,Maker<Entity>::MakerPtr ,std::less<std::string>,std::allocator<std::pair<const std::string,Maker<Entity>::MakerPtr >>,false> ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(105) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled with [ _Traits=std::_Tmap_traits<std::string,Maker<Entity>::MakerPtr ,std::less<std::string>,std::allocator<std::pair<const std::string,Maker<Entity>::MakerPtr >>,false> ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(77) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled with [ _Traits=std::_Tmap_traits<std::string,Maker<Entity>::MakerPtr ,std::less<std::string>,std::allocator<std::pair<const std::string,Maker<Entity>::MakerPtr >>,false> ] c:\Documents and Settings\Sami Hamlaoui\My Documents\Visual Studio Projects\Jail Break v1b\Source\Utility\Maker.h(66) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled with [ _Kty=std::string, _Ty=Maker<Entity>::MakerPtr ] c:\Documents and Settings\Sami Hamlaoui\My Documents\Visual Studio Projects\Jail Break v1b\Source\Game\EntityMaker.h(32) : see reference to class template instantiation 'Maker<Object>' being compiled with [ Object=Entity ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1170) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1170) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\utility(73) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\utility(73) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\utility(73) : see declaration of 'std::operator`<'' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139) : error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator Only EntityMaker.cpp (which is the only file that includes EntityMaker.cpp and has nothing else in it) chokes. Maker.cpp (which includes Maker.h and has nothing else in it) compiles fine. EDIT: (Solved) [Edited by - MENTAL on January 3, 2005 9:28:15 AM]

Share this post


Link to post
Share on other sites
Advertisement
No, #include <string> as SiCrane said, not <string.h>. The two are entirely different headers (one is the legacy c header for null-terminated char* string manipulation functions, the other is the C++ std namespaced string class).

Enigma

Share this post


Link to post
Share on other sites
Enigma: The first and third message were both by me. I was simply posting what I had done wrong (I had <string.h> and not <string>), hence the "D'oh!" afterwards, and appending "(Solved)" to the topic.

If anyone still reads this, it's now throwing up linker errors about m_registry not being anywhere. It's probably due to some rather obvious static mixup, but I'm bored of programming and am going to get some fresh air.

Templates. They either love you or they hate you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement