LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-16-2004, 06:47 AM   #1
rameshmiraje
LQ Newbie
 
Registered: Jun 2004
Posts: 2

Rep: Reputation: 0
Lightbulb 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
 
Old 06-16-2004, 08:43 AM   #2
rameshmiraje
LQ Newbie
 
Registered: Jun 2004
Posts: 2

Original Poster
Rep: Reputation: 0
It works fine on VC++ 6.0.
I have problem on Red hat. Please let me know the answer.

Thanks,
Ramesh
 
Old 06-20-2004, 01:50 PM   #3
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
You have a function that returns a SDBCmdKey* and you are trying to return an iterator.

The reason you are getting these errors is that whoever wrote the code on VC6 has made the assumption that a vector iterator is a pointer, which is technically incorrect.

You need to dereference the iterator first and get a pointer from there or use a traits class to write compiler specific code.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stl iterator woes Config Programming 4 06-23-2004 05:31 PM
_gnu Iterator Error-g++ ashwinipahuja Programming 4 05-26-2004 11:17 PM
Event driven object-to-object: C++ template class mecanism ( NOT STL or STDC++) bretzeltux Programming 2 12-23-2003 02:45 PM
returning a reference to Object C++ chens_83 Programming 3 10-10-2003 09:16 PM
Returning an object Mohsen Programming 12 08-07-2003 02:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration