CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    Usage problem on std::unordered_map

    There is an error saying that unordered_map has no associated operator '->'
    Any ideas why?
    Thanks
    Jack

    Code:
    #ifndef _OGREDETOURCROWDBASE_H_
    #define _OGREDETOURCROWDBASE_H_
    
    class OgreDetourCrowdBase {
    public:
        virtual Ogre::Real getAgentHeight(void) = 0;  
        virtual Ogre::Real getAgentRadius(void) = 0;
        virtual int getNbAgents(void) { return 0; }
        virtual int getMaxNbAgents(void) { return 0; }
    };
    
    
    #endif
    
    std::unordered_map<std::string, OgreDetourCrowdBase*> mDetourCrowd;
    
    OgreDetourCrowdBase *detourCrowd = new OgreDetourCrowd(mRecast);
    OgreDetourCrowdBase *detourCrowdCB = new OgreDetourCrowdCB(mRecastCB);
    OgreDetourCrowdBase *detourCrowdVNA = new OgreDetourCrowdVNA(mRecastVNA);
    OgreDetourCrowdBase *detourCrowdLorry = new OgreDetourCrowdLorry(mRecastLorry);
    
    mDetourCrowd["Worker"] = detourCrowd;
    mDetourCrowd["CB"] = detourCrowdCB;
    mDetourCrowd["VNA"] = detourCrowdVNA;
    mDetourCrowd["Lorry"] = detourCrowdLorry;
    
    ObjectBase *OgreRecastApplication::createOperators(Ogre::String name, Ogre::Vector3 position) {
    	if(mDetourCrowd["Worker"]->getNbAgents() >= mDetourCrowd["Worker"]->getMaxNbAgents()) {
            Ogre::LogManager::getSingletonPtr()->logMessage("Error: Cannot create crowd agent for new Worker. Limit of "+Ogre::StringConverter::toString(mDetourCrowd->getMaxNbAgents())+" reached", Ogre::LML_CRITICAL);
            throw new Ogre::Exception(1, "Cannot create crowd agent for new Worker. Limit of "+Ogre::StringConverter::toString(mDetourCrowd->getMaxNbAgents())+" reached", "OgreRecastApplication::getOrCreateCharacter("+name+")");
        }
    
         
        ObjectBase *worker = new Worker(name, mSceneMgr, mDetourCrowd, mDebugDraw, position);
        mObjects.push_back(worker);
        return worker;
    
    }
    Error 1 error C2819: type 'std::tr1::unordered_map<_Kty,_Ty>' does not have an overloaded member 'operator ->' e:\jacky\documents\visual studio 2010\projects\ogrecrowd\ogrecrowd\samples\src\ogrerecastapplication.cpp 379 1 OgreRecast
    Error 2 error C2039: 'getMaxNbAgents' : is not a member of 'std::tr1::unordered_map<_Kty,_Ty>' e:\jacky\documents\visual studio 2010\projects\ogrecrowd\ogrecrowd\samples\src\ogrerecastapplication.cpp 379 1 OgreRecast
    Error 3 error C2819: type 'std::tr1::unordered_map<_Kty,_Ty>' does not have an overloaded member 'operator ->' e:\jacky\documents\visual studio 2010\projects\ogrecrowd\ogrecrowd\samples\src\ogrerecastapplication.cpp 380 1 OgreRecast
    Error 4 error C2039: 'getMaxNbAgents' : is not a member of 'std::tr1::unordered_map<_Kty,_Ty>' e:\jacky\documents\visual studio 2010\projects\ogrecrowd\ogrecrowd\samples\src\ogrerecastapplication.cpp 380 1 OgreRecast
    Error 5 error C2664: 'Worker::Worker(Ogre::String,Ogre::SceneManager *,OgreDetourCrowd *,bool,Ogre::Vector3)' : cannot convert parameter 3 from 'std::tr1::unordered_map<_Kty,_Ty>' to 'OgreDetourCrowd *' e:\jacky\documents\visual studio 2010\projects\ogrecrowd\ogrecrowd\samples\src\ogrerecastapplication.cpp 384 1 OgreRecast
    ....
    [/code]
    Last edited by lucky6969b; June 12th, 2014 at 03:56 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Usage problem on std::unordered_map

    Reduce your program to the smallest and simplest program that you expect will compile but which demonstrates this error, then post the code.

    EDIT:
    Nevermind, I see it now: mDetourCrowd->getMaxNbAgents()

    Basically, you have a typo. Note that it occurs twice.
    Last edited by laserlight; June 12th, 2014 at 04:03 AM.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Usage problem on std::unordered_map

    Quote Originally Posted by lucky6969b
    There is an error saying that unordered_map has no associated operator '->'
    How about MSDN? Or Google?
    Compiler Error C2819
    Victor Nijegorodov

  4. #4
    Join Date
    Dec 2010
    Posts
    907

    Re: Usage problem on std::unordered_map

    main.cpp
    Code:
    #include "OgreDetourCrowdBase.h"
    #include "OgreDetourCrowdCB.h"
    #include <unordered_map>
    #include <iostream>
    
    using namespace std;
    
    std::unordered_map<std::string, OgreDetourCrowdBase*> mDetourCrowd;
    
    int main() {
    	OgreDetourCrowdBase *detourCB = new OgreDetourCrowdCB();
    
    	mDetourCrowd["CB"] = detourCB;
    
    	cout << mDetourCrowd["CB"]->getNbAgents() << endl;
    
    }
    OgreDetourCrowdBase.h
    Code:
    #ifndef _OGREDETOURCROWDBASE_H_
    #define _OGREDETOURCROWDBASE_H_
    
    class OgreDetourCrowdBase {
    public:	 
        virtual float getAgentHeight(void) = 0;
    	 
        virtual float getAgentRadius(void) = 0;
    	 
    	virtual int getNbAgents(void) { return 0; }
    	   
    	virtual int getMaxNbAgents(void) { return 0; }
    
    	 
    };
    
    
    #endif
    OgreDetourCrowdCB.h
    Code:
    #include "OgreDetourCrowdBase.h"
    
    class OgreDetourCrowdCB : public OgreDetourCrowdBase {
    	float getAgentHeight(void) { return 5.0f; }
    	 
    	float getAgentRadius(void) { return 1.0f; }
    	 
    	int getNbAgents(void) { return 10; }
    	   
    	int getMaxNbAgents(void) { return 10; }
    };
    Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional 92 1 Test

    Thank you laserlight
    Jack

  5. #5
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Usage problem on std::unordered_map

    Quote Originally Posted by lucky6969b View Post
    ...
    Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional 92 1 Test
    But is another error! Not a C2819 one!
    https://www.google.com/search?source...a=1&gws_rd=ssl
    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
    Victor Nijegorodov

  6. #6
    Join Date
    Dec 2010
    Posts
    907

    Re: Usage problem on std::unordered_map

    Thanks Victor, The bug still exists. The test program runs fine, but the program I am working on does not.
    I tried to overload the -> operator to no avail.
    Jack

  7. #7
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Usage problem on std::unordered_map

    Quote Originally Posted by lucky6969b View Post
    I tried to overload the -> operator to no avail.
    Jack
    Define "no avail".
    Victor Nijegorodov

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Usage problem on std::unordered_map

    Code:
    std::unordered_map<std::string, OgreDetourCrowdBase*> mDetourCrowd;
    Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional 92 1 Test
    Have you included <string> somewhere not shown in the code?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    Join Date
    Dec 2010
    Posts
    907

    Re: Usage problem on std::unordered_map

    Yes, all fixed, because of typos..... Thanks Victor and laserlight

  10. #10
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Usage problem on std::unordered_map

    Quote Originally Posted by lucky6969b
    I tried to overload the -> operator to no avail.
    Why do you want to overload the -> operator? It seems to me that you just need to change mDetourCrowd->getMaxNbAgents() to mDetourCrowd["Worker"]->getMaxNbAgents().
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  11. #11
    Join Date
    Dec 2010
    Posts
    907

    Re: Usage problem on std::unordered_map

    Yes, I spot that error too, it is all fine now.

  12. #12
    Join Date
    Dec 2010
    Posts
    907

    Re: Usage problem on std::unordered_map

    I didn't see that statement because it was too far down the right.
    I got it now. It's typo as you said..
    Thanks

  13. #13
    Join Date
    Jul 2013
    Posts
    576

    Re: Usage problem on std::unordered_map

    Quote Originally Posted by lucky6969b View Post
    There is an error saying that unordered_map has no associated operator '->'
    Any ideas why?
    Get the book The C++ Standard Library, second edition, by Josuttis.

    Then you can solve most C++ standard problems yourself like this one.
    Last edited by razzle; June 13th, 2014 at 04:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured