Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

c++ question, L$5000 for answer

Zhenya Vlodovic
Registered User
Join date: 23 Sep 2008
Posts: 40
01-28-2009 12:33
I have a c++ question, and it's worth L$5000 for the first correct answer. You might have to be familiar with the viewer code to help, but it looks simple enough...

I have a function that looks like this

void findstuff( const LLUUID& id)
{
std::vector<LLUUID>::iterator key = bogus.begin();
while ( key != bogus.end())
{
if ( key == id) // bit me
{
bogus.erase( key);
}
++key;
}
}

bogus is a vector that is defined like this...

std::vector<LLUUID> bogus;

What this function is supposed to do is find the UUID it's passed, in the vector 'bogus', and if found, delete it. This will not compile in Visual Studio. I get the following error on the line labeld 'bite me':

1>crap.cpp(145) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::_Vector_iterator<_Ty,_Alloc>' (or there is no acceptable conversion)

I don't know enough about c++ to fix this.

LLUUID is a class defined by Linden Lab. The argument of this function must be as shown--changing that is cheating. Casting 'key' to ( const LLUUID&;) in the line labeled 'bite me' compiles but does not succeed in finding the UUID in the vector.

L$5000 for the first correct solution.

Thanks
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-28-2009 12:34
Does "if (*key == id)" work?

edit: it's been a while since I did C++ but I think you want something like this..

void findstuff( const LLUUID& id)
{
std::vector<LLUUID>::iterator key;

integer done = 0;
while (!done)
{
done = 1;
for (key = bogus.begin(); key != bogus.end(); key++)
{
if (*key == id) // bit me
{
bogus.erase( key);
done = 0;
break;
}
}
}
}
Zhenya Vlodovic
Registered User
Join date: 23 Sep 2008
Posts: 40
01-28-2009 13:13
From: Sindy Tsure
Does "if (*key == id)" work?


Tried that. It compiles but the function doesn't work. The key is never found.

FWIW the key gets added to the vector in a function that looks like this...

void rememberstuff( const LLUUID& id)
{
bogus.push_back( id);
}

I'm now doing something like this, to see that the keys that are supposed to be the same are the same...

char k1[37];
char k2[37];
(*key).toString(k1);
id.toString(k2);
vLogFile << k1<< endl;
vLogFile << k2<< endl;

And they are, in fact, the same. So I don't understand why

*key == id

does not work.

If I have to I'll compare the strings, but that doesn't learn me anything new about c++ except that it's a pain in the butt.
Zhenya Vlodovic
Registered User
Join date: 23 Sep 2008
Posts: 40
01-28-2009 13:27
Oops. Non-ascii characters were placing text over that part of my logfile that was telling me the search was succeeding. So, *key==id does work. I'll send L5000 in just a moment. Thanks for taking the time to look at this!
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-28-2009 13:36
From: Zhenya Vlodovic
I'll send L5000 in just a moment. Thanks for taking the time to look at this!

No problem. Don't worry about the cash, though - happy to help!
Fernando Hochbaum
Registered User
Join date: 21 Oct 2008
Posts: 1
lol
01-30-2009 18:08
If u don't need the cash plz donate it to me !! lol i rly need it xD