how to call function and use return value

Started by
12 comments, last by wintertime 10 years, 8 months ago

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

Advertisement

The function doesn't return anything, so there's no return value to assign or use.

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



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

Howsabout


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

Stephen M. Webb
Professional Free Software Developer

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?

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



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.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley




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.

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.

o3o

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

This topic is closed to new replies.

Advertisement