Hi,
This is a "list iterator" problem I expect it will copy the list
iterator (l_iter) to the caller:
eg.
list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i)
{
list<HashMap>::iterator l_iter;
HashMap::iterator m_iter;
for (l_iter=macro_list.begin(); l_iter!=macro_list.end(); l_iter++) {
for (m_iter=l_iter->begin(); m_iter!=l_iter->end(); m_iter++) {
if (m_iter->first == "index") {
if (m_iter->second == i)
return l_iter;
}
}
}
}
This function just return a reference to the caller, how can I make
modification so that the function will make a copy of the l_iter to the
caller?
Thanks
Sam 7 4315
sam wrote: Hi,
This is a "list iterator" problem I expect it will copy the list iterator (l_iter) to the caller: eg. list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i) { list<HashMap>::iterator l_iter; HashMap::iterator m_iter; for (l_iter=macro_list.begin(); l_iter!=macro_list.end(); l_iter++) { for (m_iter=l_iter->begin(); m_iter!=l_iter->end(); m_iter++) { if (m_iter->first == "index") { if (m_iter->second == i) return l_iter; } } } }
This function just return a reference to the caller,
Why would it? I don't see any reference in your code at all.
how can I make modification so that the function will make a copy of the l_iter to the caller?
It already does. What makes you believe it doesn't?
"sam" <sam++@--.com> wrote in message news:d4**********@news.hgc.com.hk... Hi,
This is a "list iterator" problem I expect it will copy the list iterator (l_iter) to the caller: eg. list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i) { list<HashMap>::iterator l_iter; HashMap::iterator m_iter; for (l_iter=macro_list.begin(); l_iter!=macro_list.end(); l_iter++) { for (m_iter=l_iter->begin(); m_iter!=l_iter->end(); m_iter++) { if (m_iter->first == "index") { if (m_iter->second == i) return l_iter; } } } }
This function just return a reference to the caller, how can I make modification so that the function will make a copy of the l_iter to the caller?
It already *does* return a copy. It's return type is an iterator, not a
reference to one, and the return statement says to return a local variable's
value, which means to copy that value and return it.
But... from what I see, if the "find" fails, you're missing a return
statement at the end there. You need to return something in the case where
it's not found (or else throw an exception, I suppose).
-Howard
Rolf Magnus wrote: sam wrote:
Hi,
This is a "list iterator" problem I expect it will copy the list iterator (l_iter) to the caller: eg. list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i) { list<HashMap>::iterator l_iter; HashMap::iterator m_iter; for (l_iter=macro_list.begin(); l_iter!=macro_list.end(); l_iter++) { for (m_iter=l_iter->begin(); m_iter!=l_iter->end(); m_iter++) { if (m_iter->first == "index") { if (m_iter->second == i) return l_iter; } } } }
This function just return a reference to the caller,
Why would it? I don't see any reference in your code at all.
how can I make modification so that the function will make a copy of the l_iter to the caller?
It already does. What makes you believe it doesn't?
The l_iter-> is a pointer, iterator is a type of pointer?
Sam.
1. Iterators are usually implemented as pointers. But they do not have to.
2. Do not use postfix increment operator for objects if it is not necessary.
3. Your function must have a return statement for each case. Even if your
list is empty.
-Chris
"sam" <sam++@--.com> schrieb im Newsbeitrag
news:d4**********@news.hgc.com.hk... Rolf Magnus wrote:
sam wrote:
Hi,
This is a "list iterator" problem I expect it will copy the list iterator (l_iter) to the caller: eg. list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i) { list<HashMap>::iterator l_iter; HashMap::iterator m_iter; for (l_iter=macro_list.begin(); l_iter!=macro_list.end(); l_iter++)
{ for (m_iter=l_iter->begin(); m_iter!=l_iter->end(); m_iter++) { if (m_iter->first == "index") { if (m_iter->second == i) return l_iter; } } } }
This function just return a reference to the caller,
Why would it? I don't see any reference in your code at all.
how can I make modification so that the function will make a copy of the l_iter to the caller?
It already does. What makes you believe it doesn't? The l_iter-> is a pointer, iterator is a type of pointer?
Sam.
Please don't top-post.
Christian Meier wrote: 1. Iterators are usually implemented as pointers.
No, they aren't. The only iterators that can be implemented as pointers are
those for std::vector, and even for those, it varies. In g++, e.g., they
aren't.
sam wrote: Rolf Magnus wrote:
sam wrote:
Hi,
This is a "list iterator" problem I expect it will copy the list iterator (l_iter) to the caller: eg. list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i) { list<HashMap>::iterator l_iter; HashMap::iterator m_iter; for (l_iter=macro_list.begin(); l_iter!=macro_list.end(); l_iter++) { for (m_iter=l_iter->begin(); m_iter!=l_iter->end(); m_iter++) { if (m_iter->first == "index") { if (m_iter->second == i) return l_iter; } } } }
This function just return a reference to the caller,
Why would it? I don't see any reference in your code at all.
how can I make modification so that the function will make a copy of the l_iter to the caller?
It already does. What makes you believe it doesn't? The l_iter-> is a pointer,
l_iter is an iterator, not a pointer. And a pointer is not a reference.
iterator is a type of pointer?
No. It just shares some of its behavior with that of a pointer. Anyway, I'm
not sure what you want now. Do you want to return l_iter? Or do you want to
return a reference or a pointer to the element of your container that it's
associated with? Or do you want to make a copy of that element and return
that?
Currently, you're returning a copy of l_iter (i.e. the iterator itself).
Rolf Magnus wrote: sam wrote:
Rolf Magnus wrote:
sam wrote: Hi,
This is a "list iterator" problem I expect it will copy the list iterator (l_iter) to the caller: eg. list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i) { list<HashMap>::iterator l_iter; HashMap::iterator m_iter; for (l_iter=macro_list.begin(); l_iter!=macro_list.end(); l_iter++) { for (m_iter=l_iter->begin(); m_iter!=l_iter->end(); m_iter++) { if (m_iter->first == "index") { if (m_iter->second == i) return l_iter; } } } }
This function just return a reference to the caller,
Why would it? I don't see any reference in your code at all. how can I make modification so that the function will make a copy of the l_iter to the caller?
It already does. What makes you believe it doesn't?
The l_iter-> is a pointer,
l_iter is an iterator, not a pointer. And a pointer is not a reference.
iterator is a type of pointer?
No. It just shares some of its behavior with that of a pointer. Anyway, I'm not sure what you want now. Do you want to return l_iter? Or do you want to return a reference or a pointer to the element of your container that it's associated with? Or do you want to make a copy of that element and return that?
At the moment, I have to return *l_iter to HashMap::iterator, otherwise
I will get garbage from the returning item. I may be need to re-test it
again and see if this is really the case or caused by something else.
Sam.
Currently, you're returning a copy of l_iter (i.e. the iterator itself). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sks_cpp |
last post by:
map<int, Drive*> dMap;
list<Drive*> dList;
copy( dMap.begin(), dMap.end(), back_inserter(dList) ); // incorrect
The above will not because value_type of dMap is different than dList.
Now, I...
|
by: Vince |
last post by:
Hi,
I have replaced my BYTE* by a vector<BYTE> and before I used to do :
void CCardRecord::GetRecData(int nOffset, int nDataSize, CString& csValue)
{
BYTE *pTmp = NULL;
pTmp = new BYTE;...
|
by: Eric Lilja |
last post by:
Hello!
Consider the following complete program (with sample output). There's
something wrong with my call to std::copy() in the copy constructor of
the Unit class. It fails to copy the list. I...
|
by: vj |
last post by:
Hi! I recently came across this intresting behaviour shown by Visual
C++ 6.0 compiler regarding Copy Constructors. Please tell me that is
this the standard behaviour shown by all compilers or its...
|
by: Ryan Liu |
last post by:
Hi,
I heard foreach is slower then use loop directly, is that really true?
When loop though a list in a multiple thread environment, is that a good
practice to copy this list to an array the...
| |
by: Scott Gifford |
last post by:
Hello,
I'm working on an providing an iterator interface to a database. The
basic thing I'm trying to accomplish is to have my iterator read rows
from the database and return constructed...
|
by: jgscott |
last post by:
I've been trawling around for an answer to this question and thought
I'd try here. I have a class Graph, which has a std::list<Nodeas a
class member. Node it itself a class that makes extensive...
|
by: Peng Yu |
last post by:
Hi,
I'm wondering if the following assignment is lazy copy or not?
Thanks,
Peng
std::vector<intv.
v.push_back(1);
v.push_back(2);
|
by: =?ISO-8859-1?Q?Marcel_M=FCller?= |
last post by:
Hi,
is there a way to avoid the automatic copy constructor generation. I do
not want the object to be non-copyable. I simply do not want that
copying is done by the default copy constructor. But...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |