-
June 12th, 2014, 03:46 AM
#1
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.
-
June 12th, 2014, 03:54 AM
#2
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.
-
June 12th, 2014, 04:07 AM
#3
Re: Usage problem on std::unordered_map
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
-
June 12th, 2014, 04:12 AM
#4
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
-
June 12th, 2014, 04:19 AM
#5
Re: Usage problem on std::unordered_map
Originally Posted by lucky6969b
...
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
-
June 12th, 2014, 05:01 AM
#6
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
-
June 12th, 2014, 05:03 AM
#7
Re: Usage problem on std::unordered_map
Originally Posted by lucky6969b
I tried to overload the -> operator to no avail.
Jack
Define "no avail".
Victor Nijegorodov
-
June 12th, 2014, 05:07 AM
#8
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)
-
June 12th, 2014, 05:07 AM
#9
Re: Usage problem on std::unordered_map
Yes, all fixed, because of typos..... Thanks Victor and laserlight
-
June 12th, 2014, 05:08 AM
#10
Re: Usage problem on std::unordered_map
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().
-
June 12th, 2014, 05:08 AM
#11
Re: Usage problem on std::unordered_map
Yes, I spot that error too, it is all fine now.
-
June 12th, 2014, 05:09 AM
#12
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
-
June 13th, 2014, 04:16 PM
#13
Re: Usage problem on std::unordered_map
Originally Posted by lucky6969b
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|