Sign in to follow this  

vectorX*::insert() returning X** const

This topic is 3314 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

typedef std::map<string, Js::JType*> ElemMap;
ElemMap list;
vector<Js::JType*> clones;
.....
ElemMap::iterator appendClone(const string& key, Js::JType* heapObj){
  return list.insert(make_pair(key, &(*clones.insert(clones.end(), heapObj)) )).first;//Error here in this line
}
The above mentioned line is firing the following error
jobject.h:89: instantiated from here
/usr/include/c++/4.3/bits/stl_pair.h:106: error: cannot convert 'Js::JType** const' to 'Js::JType*' in initialization
I am also including that line of stl_pair.h which means
&(*clones.insert(clones.end(), heapObj))
is returning Js::JType** const Instead of Js::JType*
      template<class _U1, class _U2>
        pair(const pair<_U1, _U2>& __p)
	: first(__p.first),
	  second(__p.second) { }//106
Here is the code for Js::JType::clone()
virtual Js::JType* clone() const {return new Js::JType(*this);}

Share this post


Link to post
Share on other sites
Blegggh. That is one ugly-ass line of code. Break it into a few lines for readability's sake. FWIW, though, your problem is that you're explicitly finding the address of the just-inserted vector item, despite the fact that what you probably actually want is the item (a pointer) itself.

Share this post


Link to post
Share on other sites
If I break it into some line it would be:
ElemMap::iterator appendClone(const string& key, Js::JType* heapObj){
Js::JType* __tmp = &(*clones.insert(clones.end(), heapObj));
return list.insert(make_pair(key, __tmp )).first;//Error here in this line
}

Now how to solve it.
clones.insert(clones.end(), heapObj)
returns an iterator which is dereferenced by * operator and I am again getting the Js::JType* by referencing it. should I call operator->() Instead of doing it in this way ??

Share this post


Link to post
Share on other sites
I think you meant to say return list.insert(make_pair(key, heapObj)).first;
Ya that works . actually I was trying to write terse code in one line. However why my insert() Code is not working ??
according to the manual (If I've not misunderstood something) it should not become const.

Share this post


Link to post
Share on other sites

This topic is 3314 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this