compile error while returning STL iterator as object *
Hello friends,
I am trying to compile my code on linux (gcc version 3.2 20020903 - Red Hat Linux 8.0 3.2-7).
I have a vector of some objects. : vector <SDBCmdKey >
I am trying to return the objects stored in vector.
SDBCmdKey* SDBCommand::GetKey(char *keyName)
{
const char *temp1 ;
vector<SDBCmdKey>::iterator iter ;
for (iter = keyList->begin(); iter != keyList->end(); iter++)
{
temp1 = iter->GetKeyName() ;
if(strcmp(keyName, temp1) == 0)
{
return iter ;
}
}
return NULL ;
}
This works fine on Win 2000. But on linux it is giving compile error :
----------------------------------------------------------------------------------------------------
In member function `SDBCmdKey* SDBCommand::GetKey(char*)':
cannot convert `iter' from type `
__gnu_cxx::__normal_iterator<SDBCmdKey*, std::vector<SDBCmdKey,
std::allocator<SDBCmdKey> > >' to type `SDBCmdKey*'
----------------------------------------------------------------------------------------------------
I tried to use 'reinterpret_cast' to cast the iter pointer to SDBCmdKey * before returning, but doesn't work.
Please let me know how can I correct this. .
Thanks,
Ramesh
|