Hi everyone,
I am a newbie to C++ programming and am running into iterator problems..here are the snippets and the error:
//First, I have a template class called SimpleList that provides linked list functionality with functions like push, pop etc..The idea is to create stack, queues of diff. types (like char, int etc.)
~~bunch of code in between~
//function to search a list for a particular SimipleList object
217 template <class type> string srch_list(list<SimpleList<type> *>
. &list_name, string srch_name)
. {
. string condition;
. typename list<type>::const_iterator iter;
221 for(iter = list_name.begin(); iter != list_name.end(); iter++)
. {
. if (list_name->retn_name() == srch_name)
. condition = "true";
}
return condition;
227 }
//Near the end of the program, I have made a linked list of pointers to SimpleList of objects eg. there is a linked list with pointers to SimpleList objects(eg. of type int)
list<SimpleList<int> *> listSLi;
~code~
//I am calling the function with the line
string condition2;
312 condition2 = srch_list(listSLi, name_stq); //name_stq is the name of stack
I want to search
//I push SimpliList objects into listSLi later on..
But I get the error
ds_projectfinal.cpp: In function `std::string srch_list(std::list<SimpleList<typ
e>*, std::allocator<SimpleList<type>*> >&, std::string) [with type = int]':
ds_projectfinal.cpp:312: instantiated from here
ds_projectfinal.cpp:221: error: no match for 'operator=' in 'iter = (+list_name)
->std::list<_Tp, _Alloc>::begin [with _Tp = SimpleList<int>*, _Alloc = std::allo
cator<SimpleList<int>*>]()'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_list.h:188: note: candida
tes are: std::_List_const_iterator<int>& std::_List_const_iterator<int>::operato
r=(const std::_List_const_iterator<int>&)
ds_projectfinal.cpp:312: instantiated from here
ds_projectfinal.cpp:221: error: no match for 'operator!=' in 'iter != (+list_nam
e)->std::list<_Tp, _Alloc>::end [with _Tp = SimpleList<int>*, _Alloc = std::allo
cator<SimpleList<int>*>]()'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_list.h:254: note: candida
tes are: bool std::_List_const_iterator<_Tp>::operator!=(const std::_List_const_
iterator<_Tp>&) const [with _Tp = int]
I would be grateful if someone could enlighten me with some C++ light...
5 1527
I changed the iterator to
template <class type> string srch_list(list <type> &list_name, std::string srch_name)
{
string condition;
typename list<type>::const_iterator iter;
for(iter = (*list_name).begin(); iter != (*list_name).end(); iter++)
{
if ((*list_name)->retn_name() == srch_name)
condition = "true";
}
return condition;
}
//with the function being called as
condition = srch_list(listSLi, name_stq);
so, the previous error is gone but there is something else..something more sinister (joking)... but something I cannot make sense of:
It gives me the following error on compiling--
/cygdrive/c/DOCUME~1/Shrestha/LOCALS~1/Temp/ccfdnGQN.o:ds_projectfinal.cpp:(.tex
t+0x9a8): undefined reference to `std::basic_string<char, std::char_traits<char>
, std::allocator<char> > srch_list<int>(std::list<SimpleList<int>*, std::allocat
or<SimpleList<int>*> >&, std::basic_string<char, std::char_traits<char>, std::al
locator<char> >)'
/cygdrive/c/DOCUME~1/Shrestha/LOCALS~1/Temp/ccfdnGQN.o:ds_projectfinal.cpp:(.tex
t+0xdf5): undefined reference to `std::basic_string<char, std::char_traits<char>
, std::allocator<char> > srch_list<int>(std::list<SimpleList<int>*, std::allocat
or<SimpleList<int>*> >&, std::basic_string<char, std::char_traits<char>, std::al
locator<char> >)'
collect2: ld returned 1 exit status
Does not anyone have an idea what is going on?
I changed the above snippet of code to
template <class type>
string srch_list(std::list <type> &list_name, std::string srch_name)
{
string condition;
typename list<type>::const_iterator iter;
for(iter = list_name.begin(); iter != list_name.end(); iter++)
{
if (iter->retn_name() == srch_name)
condition = "true";
}
return condition;
}
//retn_name is a public function in SimpleList base class that returns the private //data member that stores the name of the SimpleList.
//And now the error is:
ds_projectfinal.cpp: In function `std::string srch_list(std::list<type, std::all
ocator<_CharT> >&, std::string) [with type = SimpleList<int>*]':
ds_projectfinal.cpp:340: instantiated from here
ds_projectfinal.cpp:241: error: request for member `retn_name' in `*(&iter)->std
::_List_const_iterator<_Tp>::operator-> [with _Tp = SimpleList<int>*]()', which
is of non-class type `SimpleList<int>* const'
I am having fun talking to myself, but it would be more enjoyable if someone joined me....
If someone could point me in the right direction, it would be really appreciated.
forgot to mention:
line 340 condition = srch_list(listSLi, name_stq);//which calls the function
~code~
template <class type>
string srch_list(std::list <type> &list_name, std::string srch_name)
{
string condition;
typename list<type>::const_iterator iter;
for(iter = list_name.begin(); iter != list_name.end(); iter++)
{
linen 241 if (iter->retn_name() == srch_name)
condition = "true";
}
return condition;
}
HI,
I went through ur code.
The problem is u ra ecalling the function (iter->retn_name() == srch_name)
I think this cant be be done..
Try to access the value directly and i think ur problem will be solved.
Thanks
Raghuram
Thanx gpraghuram,
Well, the problem was that I was trying to access retn_name in iter but lo and behold iter is a pointer and it doesn't have retn_name. What iter points to has the function so I changed the iter in line 241 to (*iter) -> retn_name and everything is fine. By fine I mean it compiles, it still doesn't do what I want it to.
Anyway, thanx to everyone for helping sp. gpraghuram....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Grant Edwards |
last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273
Alan Kay said something I really liked, and I think it applies
equally well to Python as well as the languages...
|
by: CoolPint |
last post by:
I am trying to write a generic heapsort (of course as a self-exercise)
with Iterator interface: something like blow....
But I got into trouble finding out the Iterator to the Child node. If...
|
by: Michael Klatt |
last post by:
I am trying to write an iterator for a std::set that allows the
iterator target to be modified. Here is some relvant code:
template <class Set> // Set is an instance of std::set<>
class...
|
by: Lorenzo Castelli |
last post by:
This is an old problem of mine.
Basically I have an abstract base class which represents a generic iterator
over a collection of elements, and various derived classes that implement
the...
|
by: mailforpr |
last post by:
Hi.
Let me introduce an iterator to you, the so-called "Abstract Iterator"
I developed the other day.
I actually have no idea if there's another "Abstract Iterator" out
there, as I have never...
|
by: T.A. |
last post by:
I understand why it is not safe to inherit from STL containers, but I have
found (in SGI STL documentation) that for example bidirectional_iterator
class can be used to create your own iterator...
|
by: mailforpr |
last post by:
How do I do that?
The thing is, the only information I have about the iterator is the
iterator itself. No container it is belonging to or anything. Like
template<Iteratorvoid...
|
by: David Bilsby |
last post by:
All
Apologies for cross posing this but I am not sure if this is a VC 8 STL
bug or simply an invalid use of the iterator.
I have a PCI card access class which basically abstracts a third party...
|
by: mkborregaard |
last post by:
Hi,
I have the weirdest problem, and I can not see what is going wrong.
I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very...
|
by: Luis Zarrabeitia |
last post by:
Hi there.
For most use cases I think about, the iterator protocol is more than enough.
However, on a few cases, I've needed some ugly hacks.
Ex 1:
a = iter() # assume you got the iterator...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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: 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...
| |