Jump to content
  • Advertisement
Sign in to follow this  
FGFS

how to call function and use return value

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

Hi

how to call and use the return value of:

----

void SDatabase::getNdb(const std::string &id, StdWaypointList *list)
{
    int cnt = m_ndb_map.count(id);
    if (cnt != 0) {
        NdbMapIterator it = m_ndb_map.find(id);
        int i;
        for (i = 0; i < cnt; i++) {
            Waypoint *wpt = (*it).second->asWaypoint();
            list->push_back(wpt);
            it++;
        }
    }
};

-----

If I try like:

           StdWaypointList *testlist;
           it4->second = SDatabase::getNdb(msg,testlist);

I get:

void value not ignored as it ought to be

Many thanks

 

Share this post


Link to post
Share on other sites
Advertisement

yes I see void but how should it be used then? Rewrite returning StdWaypointList? How to call it?

Share this post


Link to post
Share on other sites


yes I see void but how should it be used then? Rewrite returning StdWaypointList? How to call it?

 

Howsabout

SDatabase::getNdb(msg, &it4->second);

Share this post


Link to post
Share on other sites

I have no idea what that function is, but if it takes two parameters and returns nothing, then that is apparently how it should be used. What do you expect it to return since you assign its apparent return value to something?

Share this post


Link to post
Share on other sites

Seems like the possibly undocumented/badly named method needs to return more than 1 thing and thats why those are put into the list it takes as second argument, but OP didnt look closely enough to notice.

           StdWaypointList *testlist;
           SDatabase::getNdb(msg,testlist);
           // now check whats inside the testlist and use it

Share this post


Link to post
Share on other sites

 



yes I see void but how should it be used then? Rewrite returning StdWaypointList? How to call it?

 

Howsabout

SDatabase::getNdb(msg, &it4->second);

 

That looks good to me. Whatever it4 is (I think it's some kind of map/multimap from other posts by OP).

 

The other methods, passing an uninitialised pointer to an StdWaypointList, is just going to crash as soon as it tries to push_back to the list, since testlist doesn't hold the address of a constructed StdWaypointList.

Share this post


Link to post
Share on other sites




Howsabout

SDatabase::getNdb(msg, &it4->second);

 

that returns:

Multiple markers at this line
    - Invalid arguments ' Candidates are: void getNdb(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
     std::vector<Waypoint *,std::allocator<Waypoint *>> *) '
    - no matching function for call to ‘SDatabase::getNdb(const char*&, Ndb**)’
 

the declaration:

typedef vector<Waypoint*> StdWaypointList;

 

Thanks for ideas.

Share this post


Link to post
Share on other sites

What type is it4->second?

 

when you do "&it4->second", it4->second should be a vector, not a pointer to a vector. If it is a pointer to a vector already, remove the "&".

 

Also, with the code you were first trying to do it with, the StdWaypointlist was not allocated, however the functions expects a pointer to a initialized StdWaypointList. So you would need to allocate a vector first. But thats probably what you werent supposed to do anyways.

Share this post


Link to post
Share on other sites

Yes, but how? I only see in another function:

 

   Waypoint wpt = parseWaypoint(subElem, Waypoint::FLAG_SID);

 

Cannot find any StdWaypointList. Probably that's the function doing? Does it need a return value to increment the list?

 

As for it4 I do before calling that getNdb:

      for (multimap<string, Ndb*>::iterator it4 = m_ndb_map.begin() ; it4 != m_ndb_map.end(); ++it4)
       {

 

Thanks again

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!